]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
importer: Sync geofeeds
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 27 Sep 2022 07:59:37 +0000 (07:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 27 Sep 2022 16:47:17 +0000 (16:47 +0000)
Geofeeds are kept in a separate table to only fetch them once per URL.
This needs to be kept in sync which is done before we update any feeds.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/scripts/location-importer.in

index 014f3b65f60fe99808533c5a9d869c39c64b9219..12035f17856226adfa4b3f8b9a0cc165cc140e5c 100644 (file)
@@ -1279,6 +1279,38 @@ class CLI(object):
                                yield line
 
        def handle_update_geofeeds(self, ns):
+               # Sync geofeeds
+               with self.db.transaction():
+                       # Delete all geofeeds which are no longer linked
+                       self.db.execute("""
+                               DELETE FROM
+                                       geofeeds
+                               WHERE
+                                       NOT EXISTS (
+                                               SELECT
+                                                       1
+                                               FROM
+                                                       network_geofeeds
+                                               WHERE
+                                                       geofeeds.url = network_geofeeds.url
+                                       )""",
+                       )
+
+                       # Copy all geofeeds
+                       self.db.execute("""
+                               INSERT INTO
+                                       geofeeds(
+                                               url
+                                       )
+                               SELECT
+                                       url
+                               FROM
+                                       network_geofeeds
+                               ON CONFLICT (url)
+                                       DO NOTHING
+                               """,
+                       )
+
                # Fetch all Geofeeds that require an update
                geofeeds = self.db.query("""
                        SELECT