Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check modified time for path #460

Merged
merged 7 commits into from
Jan 22, 2025
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/aiogram_dialog/context/media_storage.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
from typing import Optional

from aiogram.types import ContentType
Expand All @@ -19,7 +20,15 @@ async def get_media_id(
) -> Optional[MediaId]:
if not path and not url:
return None
return self.cache.get((path, url, type))
return self.cache.get((path, url, type, self._get_file_mtime(path)))

def _get_file_mtime(self, path: Optional[str]) -> Optional[float]:
if not path:
return None
p = Path(path)
if not p.exists():
return None
return Path(path).stat().st_mtime

async def save_media_id(
self,
Expand All @@ -30,4 +39,4 @@ async def save_media_id(
) -> None:
if not path and not url:
return
self.cache[(path, url, type)] = media_id
self.cache[(path, url, type, self._get_file_mtime(path))] = media_id
Loading