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

@@ -49,6 +49,10 @@ async def get_creatives_analytics(
creative_stats: dict[UUID, CreativeStats] = {cr.id: CreativeStats() for cr in creatives}
# Batch fetch views data for all posts
post_ids = [p.post.id for p in placements if p.post]
views_map = await self.database.get_latest_views_data_batch(post_ids) if post_ids else {}
for p in placements:
stats = creative_stats.get(p.creative_id)
if stats is None:
@@ -56,7 +60,12 @@ async def get_creatives_analytics(
stats.total_cost += p.cost if p.cost is not None else 0
stats.total_subscriptions += p.subscriptions_count
stats.total_views += p.views_count if p.views_count is not None else 0
# Get views from batch data
if p.post and p.post.id in views_map:
views_count = views_map[p.post.id][0]
stats.total_views += views_count
stats.placements_count += 1
result = []