This commit is contained in:
@@ -764,34 +764,23 @@ async def get_author(
|
||||
if "stat" in cached_author:
|
||||
author_dict["stat"] = cached_author["stat"]
|
||||
|
||||
# ВСЕГДА используем новый резолвер для получения полной статистики
|
||||
try:
|
||||
# Используем новый резолвер для получения полной статистики
|
||||
filter_by: AuthorsBy = {}
|
||||
if slug:
|
||||
filter_by["slug"] = slug
|
||||
elif author_id:
|
||||
filter_by["id"] = author_id # author_id уже int
|
||||
if not author_dict or not author_dict.get("stat"):
|
||||
# Используем ту же логику что и в load_authors_by
|
||||
try:
|
||||
filter_by: AuthorsBy = {}
|
||||
if slug:
|
||||
filter_by["slug"] = slug
|
||||
elif author_id:
|
||||
filter_by["id"] = author_id
|
||||
|
||||
logger.debug(f"Calling get_authors_with_stats with filter: {filter_by}")
|
||||
authors_with_stats = await get_authors_with_stats(limit=1, offset=0, by=filter_by)
|
||||
|
||||
if authors_with_stats and len(authors_with_stats) > 0:
|
||||
author_dict = authors_with_stats[0]
|
||||
logger.debug(f"Got author with stats: shouts={author_dict.get('stat', {}).get('shouts', 'missing')}")
|
||||
|
||||
# Фильтруем данные согласно правам доступа
|
||||
if not is_admin:
|
||||
# Убираем защищенные поля для не-админов
|
||||
protected_fields = ["email", "phone"]
|
||||
for field in protected_fields:
|
||||
author_dict.pop(field, None)
|
||||
|
||||
# Кэшируем полные данные для админов
|
||||
_t = asyncio.create_task(cache_author(author_dict))
|
||||
else:
|
||||
logger.warning(f"No author found with filter: {filter_by}")
|
||||
# Fallback to basic author data without stats
|
||||
authors_with_stats = await get_authors_with_stats(limit=1, offset=0, by=filter_by)
|
||||
if authors_with_stats and len(authors_with_stats) > 0:
|
||||
author_dict = authors_with_stats[0]
|
||||
# Кэшируем полные данные
|
||||
_t = asyncio.create_task(cache_author(author_dict))
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting author stats: {e}")
|
||||
# Fallback к старому методу
|
||||
with local_session() as session:
|
||||
if slug:
|
||||
author = session.query(Author).filter_by(slug=slug).first()
|
||||
@@ -799,17 +788,6 @@ async def get_author(
|
||||
author = session.query(Author).filter_by(id=author_id).first()
|
||||
if author:
|
||||
author_dict = author.dict(is_admin)
|
||||
logger.debug(f"Using fallback author dict: {author_dict.get('name', 'unknown')}")
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting author stats: {e}")
|
||||
# Fallback to basic author data without stats
|
||||
with local_session() as session:
|
||||
if slug:
|
||||
author = session.query(Author).filter_by(slug=slug).first()
|
||||
else:
|
||||
author = session.query(Author).filter_by(id=author_id).first()
|
||||
if author:
|
||||
author_dict = author.dict(is_admin)
|
||||
except ValueError:
|
||||
pass
|
||||
except Exception as exc:
|
||||
|
||||
Reference in New Issue
Block a user