feat: убираем денормализацию (антипреждевременная оптимизация)

This commit is contained in:
Artem Tsyrulnikov
2025-12-16 10:04:20 +03:00
parent 2339471956
commit 18b30eaf7f
26 changed files with 295 additions and 232 deletions

View File

@@ -53,13 +53,17 @@ async def get_creatives_analytics(
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 {}
# Batch fetch subscriptions counts
placement_ids = [p.id for p in placements]
subscriptions_counts = await self.database.count_subscriptions_by_placement_batch(placement_ids)
for p in placements:
stats = creative_stats.get(p.creative_id)
if stats is None:
continue
stats.total_cost += p.cost if p.cost is not None else 0
stats.total_subscriptions += p.subscriptions_count
stats.total_subscriptions += subscriptions_counts.get(p.id, 0)
# Get views from batch data
if p.post and p.post.id in views_map: