Skip to content

Commit 64f5681

Browse files
committed
fix(cache): check if the model has been deleted already
1 parent ad4749e commit 64f5681

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

toggl_api/meta/cache/json_cache.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class JSONSession:
6868

6969
def refresh(self, path: Path) -> bool:
7070
if path.exists() and path.stat().st_mtime_ns > self.modified:
71-
self.data = self._diff(self._load(path)["data"])
71+
self.data = self._diff(self._load(path)["data"], path.stat().st_mtime_ns)
72+
self.modified = path.stat().st_mtime_ns
7273
return True
7374
return False
7475

@@ -87,7 +88,7 @@ def commit(self, path: Path) -> None:
8788

8889
self.modified = path.stat().st_mtime_ns
8990

90-
def _diff(self, comp: list[TogglClass]) -> list[TogglClass]:
91+
def _diff(self, comp: list[TogglClass], mtime: int) -> list[TogglClass]:
9192
old_models = {m.id: m for m in self.data}
9293
new_models = {m.id: m for m in comp}
9394

@@ -104,7 +105,7 @@ def _diff(self, comp: list[TogglClass]) -> list[TogglClass]:
104105
new_data.append(old)
105106
elif new and old and new.timestamp >= old.timestamp:
106107
new_data.append(new)
107-
elif old:
108+
elif old and old.timestamp.timestamp() * 10**9 >= mtime:
108109
new_data.append(old)
109110

110111
return new_data

0 commit comments

Comments
 (0)