diff --git a/src/usecase/analytics/get_placements_analytics.py b/src/usecase/analytics/get_placements_analytics.py index 085efb4..3b8b745 100644 --- a/src/usecase/analytics/get_placements_analytics.py +++ b/src/usecase/analytics/get_placements_analytics.py @@ -102,16 +102,14 @@ async def get_placements_analytics( allowed_project_ids=allowed_project_ids, ) - placement_post_ids = [p.id for p in placements] - post_ids = ( - [ - p.post.id - for p in placements - if hasattr(p, 'placement_posts') and p.placement_posts and p.placement_posts[0].post - ] - if placements - else [] - ) + # Extract placement_post_ids and post_ids from placement.placement_posts + placement_post_ids = [pp.id for p in placements for pp in p.placement_posts] + post_ids = [ + pp.post.id + for p in placements + for pp in p.placement_posts + if pp.post + ] views_map = await self.database.get_latest_views_data_batch(post_ids) if post_ids else {} subscriptions_counts = ( await self.database.count_subscriptions_by_placement_post_batch(placement_post_ids)