diff schema/updates/1101/01.improve_del_import.sql @ 4126:52f7264265bb

Bulk-delete tracked entries per table Especially when many entries in one table are tracked by one import, this makes declining an import a lot faster.
author Tom Gottfried <tom@intevation.de>
date Thu, 01 Aug 2019 17:02:09 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/schema/updates/1101/01.improve_del_import.sql	Thu Aug 01 17:02:09 2019 +0200
@@ -0,0 +1,17 @@
+CREATE OR REPLACE FUNCTION import.del_import(imp_id int) RETURNS void AS
+$$
+DECLARE
+    tmp RECORD;
+BEGIN
+    FOR tmp IN
+        SELECT relation, array_agg(key) AS keys
+            FROM import.track_imports
+            WHERE import_id = imp_id AND NOT deletion
+            GROUP BY relation
+    LOOP
+        EXECUTE format('DELETE FROM %s WHERE id = ANY($1)', tmp.relation)
+            USING tmp.keys;
+    END LOOP;
+END;
+$$
+LANGUAGE plpgsql;