From b10c26a20f023a7ca7fb17bc50bd1022232d14de Mon Sep 17 00:00:00 2001 From: Giacomo Sarrocco Date: Thu, 28 Sep 2023 23:44:02 +0200 Subject: [PATCH] Sync to typesense only if new stations are present --- MuoVErsi/sources/base.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/MuoVErsi/sources/base.py b/MuoVErsi/sources/base.py index 6b5f97f..4446c98 100644 --- a/MuoVErsi/sources/base.py +++ b/MuoVErsi/sources/base.py @@ -285,14 +285,19 @@ def sync_stations_typesense(self, stations: list[Station]): stations_collection.documents.delete({'filter_by': f'source:{self.name}'}) - stations_collection.documents.import_([{ + stations_to_sync = [{ 'id': station.id, 'name': station.name, 'location': [station.lat, station.lon], 'ids': station.ids, 'source': station.source, 'times_count': station.times_count - } for station in stations]) + } for station in stations] + + if not stations_to_sync: + return + + stations_collection.documents.import_(stations_to_sync) def get_stop_from_ref(self, ref) -> Station | None: stmt = select(Station) \