bypass-cache-topic
Some checks failed
Deploy on push / deploy (push) Failing after 4m57s

This commit is contained in:
2025-09-03 13:15:57 +03:00
parent 69102bb908
commit 06d4b64b1f

View File

@@ -237,9 +237,9 @@ async def get_authors_with_stats(
else:
logger.warning(f"Unknown order field: {order_value}")
else:
# Regular sorting by fields
# Regular sorting by fields (исключаем topic, так как он уже обработан выше)
for field, direction in by.items():
if field is None:
if field is None or field == "topic":
continue
column = getattr(Author, field, None)
if column:
@@ -678,13 +678,23 @@ async def get_authors_with_stats(
logger.error(f"Traceback: {traceback.format_exc()}")
raise
# Используем универсальную функцию для кеширования запросов
# Для фильтра по топику принудительно обновляем кеш (временное решение для отладки)
force_refresh = by is not None and by.get("topic") is not None
if force_refresh and by:
logger.debug(f"🚨 Force refresh enabled for topic filter: {by.get('topic')}")
# Временное решение: для фильтра по топику не используем кеш
cached_result = await cached_query(cache_key, fetch_authors_with_stats, force_refresh=force_refresh)
topic_value = None
if by is not None and (hasattr(by, "get") or isinstance(by, dict)):
topic_value = by.get("topic")
if topic_value is not None:
logger.debug(f"🚨 Topic filter detected: {topic_value}, bypassing cache")
# Вызываем функцию напрямую без кеширования
result = await fetch_authors_with_stats()
logger.debug(f"Direct result: {len(result)} authors")
return result
# Для остальных случаев используем кеш
cached_result = await cached_query(
cache_key, fetch_authors_with_stats, limit=limit, offset=offset, by=by, current_user_id=current_user_id
)
logger.debug(f"Cached result: {cached_result}")
return cached_result
@@ -845,14 +855,28 @@ async def load_authors_by(
info.context.get("is_admin", False)
# Логирование для отладки
print(f"🔍 load_authors_by called with by={by}, limit={limit}, offset={offset}")
print(f"🔍 by type: {type(by)}, content: {dict(by) if hasattr(by, 'items') else by}")
logger.debug(f"load_authors_by called with by={by}, limit={limit}, offset={offset}")
logger.debug(f"by type: {type(by)}, content: {dict(by) if hasattr(by, 'items') else by}")
# Проверяем наличие параметра order в словаре
if "order" in by:
print(f"🔍 Sorting by order={by['order']}")
logger.debug(f"Sorting by order={by['order']}")
# Проверяем наличие параметра topic
if "topic" in by:
print(f"🎯 Topic filter found: {by['topic']}")
logger.debug(f"🎯 Topic filter found: {by['topic']}")
else:
print("❌ No topic filter found in by parameters")
logger.debug("❌ No topic filter found in by parameters")
# Используем оптимизированную функцию для получения авторов
return await get_authors_with_stats(limit, offset, by, viewer_id)
result = await get_authors_with_stats(limit, offset, by, viewer_id)
logger.debug(f"get_authors_with_stats returned {len(result)} authors")
return result
except Exception as exc:
logger.error(f"{exc}:\n{traceback.format_exc()}")
return []