views-count-fix
Some checks failed
Deploy on push / deploy (push) Failing after 7s

This commit is contained in:
2025-08-27 15:22:18 +03:00
parent 29f8625617
commit 32f1fab867
4 changed files with 32 additions and 23 deletions

View File

@@ -205,11 +205,16 @@ class ViewedStorage:
if shout_slug:
return self.views_by_shout.get(shout_slug, 0)
# 🔎 Для ID ищем по всем slug'ам (пока нет прямого ID -> views mapping)
# TODO: можно добавить views_by_id кеш для оптимизации
# 🔎 Для ID ищем slug в БД и затем получаем views_count
if shout_id:
# Простое решение: возвращаем 0 если нет slug
# В production лучше добавить отдельный кеш по ID
try:
with local_session() as session:
from orm.shout import Shout
shout = session.query(Shout).where(Shout.id == shout_id).first()
if shout and shout.slug:
return self.views_by_shout.get(shout.slug, 0)
except Exception as e:
logger.warning(f"Failed to get shout slug for id {shout_id}: {e}")
return 0
return 0