Skip to content

Commit

Permalink
Don't duplicate movies in different report sections
Browse files Browse the repository at this point in the history
  • Loading branch information
booxter committed Nov 21, 2024
1 parent 666e493 commit f818623
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/letsrolld/webapi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ def _get_report_config(id):
return sections


def _execute_section_plan(db, config):
query = db.session.query(models.Film)
def _execute_section_plan(db, config, seen_films):
query = db.session.query(models.Film).filter(~models.Film.id.in_(seen_films))
if config.services:
query = query.join(models.Film.offers).filter(
models.Offer.name.in_(config.services)
Expand Down Expand Up @@ -287,15 +287,13 @@ def get(self, id):
# TODO: support multiple reports
if id != 0:
return {}, 404
return _get_report(
sections=[
webapi_models.ReportSection(
name=config.name,
films=_execute_section_plan(db_, config),
)
for config in _get_report_config(id)
]
), 200
sections = []
seen_films = set()
for config in _get_report_config(id):
films = _execute_section_plan(db_, config, seen_films)
seen_films.update(f["id"] for f in films)
sections.append(webapi_models.ReportSection(name=config.name, films=films))
return _get_report(sections=sections), 200


def _api():
Expand Down

0 comments on commit f818623

Please sign in to comment.