Move Element.__*cached variable to Artifact class
I'd suggest adding a __cached variable to the Artifact class to replace the Element variables __weak_cached and __strong_cached (or __strict_cached after the rename suggested in !1323 (comment 166065971)). And then change Artifact.cached() to return __cached, actually querying the (filesystem) cache only on the first call.
I think this would make a couple areas slightly simpler:
- In
_update_state():- Drop
__strong_cached = Noneand__weak_cached = Noneas they will be implicitly discarded by discarding the artifact objects. - Drop the first real
__weak_cachedassignment as the first call toself.__artifact.cached()will cover this. - Replace the following conditional assignments to
__strong_cachedand__weak_cachedwith unconditional calls toself.__strict_artifact.update_cached()andself.__artifact.update_cached().Artifact.update_cached()should do nothing if__cachedis alreadyTrueand otherwise ensure that the the next call toArtifact.cached()queries the (filesystem) cache again.
- Drop
-
Element._cached()could be changed to a simplereturn self.__artifact.cached()(an early return ifself.__artifactis stillNonemay be required, to be determined).
_pull_pending()'s use of self.__strong_cached should be replaced with self.__strict_artifact.cached().
In future _update_state() splitting work, the update_cached() calls could likely be moved to points where we know that we need to requery the (filesystem) cache (after pulling and after building) instead of doing it unconditionally in _update_state(). However, that can be done in a separate step as the changes above are not expected to cause a performance regression.