Skip to content

Commit

Permalink
fix: #315 avoid request when no vessel_id found (no excursion, no seg…
Browse files Browse the repository at this point in the history
…ment)
  • Loading branch information
rv2931 committed Jan 8, 2025
1 parent 091446d commit d2a91a5
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions backend/bloom/infra/repositories/repository_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,17 @@ def update_last_segments(self, session: Session, vessel_ids: list[int]) -> int:
values(last_vessel_segment=False))
session.execute(upd1)
session.flush()
last_segments = session.execute(text("""SELECT DISTINCT ON (vessel_id) s.id FROM fct_segment s
JOIN fct_excursion e ON e.id = s.excursion_id
WHERE vessel_id in :vessel_ids
ORDER BY vessel_id, timestamp_start DESC"""),
{"vessel_ids": tuple(vessel_ids)}).all()
ids = [r[0] for r in last_segments]
upd2 = update(sql_model.Segment).where(sql_model.Segment.id.in_(ids)).values(
last_vessel_segment=True)
session.execute(upd2)
ids=[]
if(vessel_ids):
last_segments = session.execute(text("""SELECT DISTINCT ON (vessel_id) s.id FROM fct_segment s
JOIN fct_excursion e ON e.id = s.excursion_id
WHERE vessel_id in :vessel_ids
ORDER BY vessel_id, timestamp_start DESC"""),
{"vessel_ids": tuple(vessel_ids)}).all()
ids = [r[0] for r in last_segments]
upd2 = update(sql_model.Segment).where(sql_model.Segment.id.in_(ids)).values(
last_vessel_segment=True)
session.execute(upd2)
return len(ids)

@staticmethod
Expand Down

0 comments on commit d2a91a5

Please sign in to comment.