Skip to content

Commit c2e6b80

Browse files
committed
fix: actually start with clean cache
The existing code didn't actually replace "self" so the first time the program launched with a stale cache, it actually kept the old cache's contents. Tested: - had a stale cache - launched OD with attached debugger - ensured cache did not have any values populated
1 parent db5e386 commit c2e6b80

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

ou_dedetai/network.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,19 @@ def _is_fresh(self) -> bool:
205205
return False
206206
return True
207207

208-
def clean_if_stale(self, force: bool = False):
208+
def ensure_fresh(self, force: bool = False) -> "CachedRequests":
209+
"""Returns a CachedRequests that is fresh
210+
211+
- Either an empty new one
212+
- Or the existing one
213+
"""
209214
if force or not self._is_fresh():
210215
logging.debug("Cleaning out cache…")
211216
self = CachedRequests(last_updated=time.time())
212217
self._write()
213218
else:
214219
logging.debug("Cache is valid")
220+
return self
215221

216222

217223
class NetworkRequests:
@@ -224,9 +230,8 @@ def __init__(
224230
force_clean: Optional[bool] = None,
225231
hook: Callable[[], None] | None = None
226232
) -> None:
227-
self._cache = CachedRequests.load()
233+
self._cache = CachedRequests.load().ensure_fresh(force=force_clean or False)
228234
self._cache._update_hook = hook
229-
self._cache.clean_if_stale(force=force_clean or False)
230235

231236
def _faithlife_product_releases(
232237
self,

0 commit comments

Comments
 (0)