Skip to content

Commit d2214ff

Browse files
committed
Optimize lookups when all tests have been loaded
refs #31831
1 parent 073a62e commit d2214ff

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

python/TestHarness/resultsstore/storedresults.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@ def __init__(
425425
# Loaded test objects
426426
self._tests: dict[TestName, StoredTestResult] = {}
427427

428+
# Whether or not we have loaded all tests
429+
self._all_tests_loaded: bool = False
430+
428431
# Sanity check on all of our methods (in order of definition)
429432
if self.check:
430433
if self._database_getter is not None:
@@ -588,8 +591,13 @@ def has_test(self, name: TestName) -> bool:
588591
"""
589592
assert isinstance(name, TestName)
590593

594+
# Check the cache first (faster lookup)
591595
if name in self._tests:
592596
return True
597+
# Not in the cache, but we've loaded all so nothing here
598+
elif self._all_tests_loaded:
599+
return False
600+
# Slower linear lookup in the test data
593601
return results_has_test(self.data, name)
594602

595603
def _find_test_data(self, id: ObjectId) -> Optional[dict]:
@@ -641,6 +649,10 @@ def query_test(self, name: TestName) -> Optional[StoredTestResult]:
641649
if value is not None:
642650
return value
643651

652+
# If all tests have been loaded, there's nothing left to check
653+
if self._all_tests_loaded:
654+
return None
655+
644656
# Find it in the data to build
645657
test_entry = None
646658
for entry in results_test_iterator(self.data):
@@ -696,6 +708,10 @@ def _find_tests_data(self, ids: list[ObjectId]) -> list[dict]:
696708

697709
def load_all_tests(self):
698710
"""Load all tests that have not been loaded from the database."""
711+
# Nothing to do if we've already loaded all
712+
if self._all_tests_loaded:
713+
return
714+
699715
# Get tests that need to be loaded; need a mapping
700716
# of id -> name so that we can go from a document
701717
# to a name when obtaining data from the database
@@ -726,6 +742,9 @@ def load_all_tests(self):
726742
]
727743
raise KeyError(f"Failed to load test results for _id={missing}")
728744

745+
# Mark that we've loaded everything
746+
self._all_tests_loaded = True
747+
729748
def get_tests(self) -> list[StoredTestResult]:
730749
"""
731750
Get all of the test results.

0 commit comments

Comments
 (0)