Add notes about _is_cache_updated logic

This commit is contained in:
Mikhail f. Shiryaev 2022-08-02 18:44:49 +02:00
parent c150fe6f0d
commit 469b7e7668
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4

View File

@ -176,12 +176,15 @@ class GitHub(github.Github):
self, cache_file: Path, obj_updated_at: Optional[datetime]
) -> Tuple[bool, object]:
cached_obj = self._get_cached(cache_file)
cache_updated = cached_obj.updated_at
if obj_updated_at is None:
obj_updated_at = datetime.now() - timedelta(hours=1)
# We don't want the cache_updated being always old,
# for example in cases when the user is not updated for ages
cache_updated = max(
datetime.fromtimestamp(cache_file.stat().st_mtime), cache_updated
datetime.fromtimestamp(cache_file.stat().st_mtime), cached_obj.updated_at
)
if obj_updated_at is None:
# When we don't know about the object is updated or not,
# we update it once per hour
obj_updated_at = datetime.now() - timedelta(hours=1)
if obj_updated_at <= cache_updated:
return True, cached_obj
return False, cached_obj