Skip to content

Commit

Permalink
Remove validate argument from update_cache.
Browse files Browse the repository at this point in the history
Locally catch the JobsCorruptedError and ignore it in the test that needs to.
  • Loading branch information
joaander committed Feb 12, 2024
1 parent 1de7155 commit d48d281
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 4 additions & 9 deletions signac/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ def _build_index(self, include_job_document=False):
raise
yield job_id, doc

def _update_in_memory_cache(self, validate=False):
def _update_in_memory_cache(self):
"""Update the in-memory state point cache to reflect the workspace."""
logger.debug("Updating in-memory cache...")
start = time.time()
Expand All @@ -1402,7 +1402,7 @@ def _update_in_memory_cache(self, validate=False):
del self._sp_cache[id_]

def _add(id_):
self._sp_cache[id_] = self._get_statepoint_from_workspace(id_, validate)
self._sp_cache[id_] = self._get_statepoint_from_workspace(id_)

to_add_chunks = _split_and_print_progress(
iterable=list(to_add),
Expand All @@ -1429,25 +1429,20 @@ def _remove_persistent_cache_file(self):
if error.errno != errno.ENOENT:
raise error

def update_cache(self, validate=True):
def update_cache(self):
"""Update the persistent state point cache.
This function updates a persistent state point cache, which
is stored in the project directory. Most data space operations,
including iteration and filtering or selection are expected
to be significantly faster after calling this function, especially
for large data spaces.
Parameters
----------
validate : bool
When True, validate that any statepoint read from disk matches the job_id.
"""
logger.info("Update cache...")
start = time.time()
cache = self._read_cache()
cached_ids = set(self._sp_cache)
self._update_in_memory_cache(validate)
self._update_in_memory_cache()
if cache is None or set(cache) != cached_ids:
fn_cache = self.fn(self.FN_CACHE)
fn_cache_tmp = fn_cache + "~"
Expand Down
8 changes: 6 additions & 2 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,11 @@ def test_rename_workspace(self):
with pytest.raises(JobsCorruptedError):
self.project.check()
# ... we reinitialize the initial job, ...
job.init()
try:
job.init()
except JobsCorruptedError:
# ... which raises the JobsCorruptedError in update_cache
pass
with pytest.raises(JobsCorruptedError):
# ... which means the repair attempt must fail.
self.project.repair()
Expand Down Expand Up @@ -2102,7 +2106,7 @@ class UpdateCacheAfterInitJob(signac.job.Job):

def init(self, *args, **kwargs):
job = super().init(*args, **kwargs)
self._project.update_cache(validate=False)
self._project.update_cache()
return job


Expand Down

0 comments on commit d48d281

Please sign in to comment.