feat: убираем денормализацию (антипреждевременная оптимизация)
This commit is contained in:
@@ -74,6 +74,10 @@ async def get_spending_analytics(
|
||||
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 {}
|
||||
|
||||
# Batch fetch subscriptions counts
|
||||
placement_ids = [p.id for p in filtered]
|
||||
subscriptions_counts = await self.database.count_subscriptions_by_placement_batch(placement_ids)
|
||||
|
||||
# Группировка по периодам
|
||||
period_data: dict[str, PeriodData] = defaultdict(PeriodData)
|
||||
|
||||
@@ -85,8 +89,9 @@ async def get_spending_analytics(
|
||||
total_cost += p.cost
|
||||
pd.cost += p.cost
|
||||
|
||||
total_subs += p.subscriptions_count
|
||||
pd.subscriptions += p.subscriptions_count
|
||||
subs_count = subscriptions_counts.get(p.id, 0)
|
||||
total_subs += subs_count
|
||||
pd.subscriptions += subs_count
|
||||
|
||||
# Get views from batch data
|
||||
if p.post and p.post.id in views_map:
|
||||
|
||||
Reference in New Issue
Block a user