размещения ручки
This commit is contained in:
@@ -36,11 +36,18 @@ async def get_placements(self: 'Usecase', input: dto.GetPlacementsInput) -> dto.
|
||||
)
|
||||
placement_post_ids = [post.id for post in placement_posts]
|
||||
subscriptions_counts = await self.database.count_subscriptions_by_placement_post_batch(placement_post_ids)
|
||||
post_ids = [placement_post.post.id for placement_post in placement_posts if placement_post.post]
|
||||
views_map = await self.database.get_latest_views_data_batch(post_ids) if post_ids else {}
|
||||
|
||||
placement_posts_by_placement_id: dict[uuid.UUID, list[dto.PlacementPostOutput]] = {}
|
||||
for placement_post in placement_posts:
|
||||
views_count = None
|
||||
if placement_post.post:
|
||||
views_count = views_map.get(placement_post.post.id, (None,))[0]
|
||||
placement_post_output = _build_placement_post_output(
|
||||
placement_post, subscriptions_counts.get(placement_post.id, 0)
|
||||
placement_post,
|
||||
subscriptions_counts.get(placement_post.id, 0),
|
||||
views_count,
|
||||
)
|
||||
if placement_post_output is None:
|
||||
continue
|
||||
@@ -49,10 +56,18 @@ async def get_placements(self: 'Usecase', input: dto.GetPlacementsInput) -> dto.
|
||||
placement_outputs = []
|
||||
for placement in placements:
|
||||
placement_output = _build_placement_output(placement)
|
||||
placement_post_output = None
|
||||
placement_posts_for_placement = placement_posts_by_placement_id.get(placement.id, [])
|
||||
if placement_posts_for_placement:
|
||||
if len(placement_posts_for_placement) > 1:
|
||||
log.warning(
|
||||
'Placement %s has %s placement_posts, returning latest', placement.id, len(placement_posts_for_placement)
|
||||
)
|
||||
placement_post_output = placement_posts_for_placement[0]
|
||||
placement_outputs.append(
|
||||
dto.PlacementWithPostsOutput(
|
||||
**placement_output.model_dump(),
|
||||
placement_posts=placement_posts_by_placement_id.get(placement.id, []),
|
||||
placement_post=placement_post_output,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user