90% сеньоров плачат на таких коммитах

This commit is contained in:
Artem Tsyrulnikov
2025-12-15 19:10:41 +03:00
parent fda91cb6d8
commit 71e5a38efc
42 changed files with 403 additions and 302 deletions

View File

@@ -70,6 +70,10 @@ async def get_spending_analytics(
subscriptions: int = 0
views: int = 0
# Batch fetch views data for all posts
post_ids = [p.post.id for p in filtered if p.post]
views_map = await self.database.get_latest_views_data_batch(post_ids) if post_ids else {}
# Группировка по периодам
period_data: dict[str, PeriodData] = defaultdict(PeriodData)
@@ -84,9 +88,11 @@ async def get_spending_analytics(
total_subs += p.subscriptions_count
pd.subscriptions += p.subscriptions_count
if p.views_count is not None:
total_views += p.views_count
pd.views += p.views_count
# Get views from batch data
if p.post and p.post.id in views_map:
views_count = views_map[p.post.id][0]
total_views += views_count
pd.views += views_count
avg_cpf = total_cost / total_subs if total_subs > 0 and total_cost > 0 else None
avg_cpm = (total_cost / total_views * 1000) if total_views > 0 and total_cost > 0 else None