From f2bb5d6654d9da53eb91d67decb80fa98c4cd5dc Mon Sep 17 00:00:00 2001 From: fly Date: Thu, 27 Aug 2020 11:06:58 +0000 Subject: [PATCH] Run import without trigger as it slows things down Signed-off-by: fly --- import-progress.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/import-progress.py b/import-progress.py index f36c942..388b874 100755 --- a/import-progress.py +++ b/import-progress.py @@ -89,12 +89,43 @@ except IOError: print("ERROR: Unable to read file") sys.exit(1) +# Drop triggers cause they slow down things massively +cursor.execute("DROP TRIGGER IF EXISTS update_second_level") + for top in status: if isinstance(status[top], dict): for second in status[top]: if isinstance(status[top][second], dict) and "status" in status[top][second]: sql = "UPDATE secondLevel SET status_id = (SELECT id FROM status WHERE name = '" + status[top][second]["status"] + "') WHERE name = '" + second + "'" cursor.execute(sql) + sql = "SELECT id FROM secondLevel WHERE name = '" + second + "'" + cursor.execute(sql) + row = cursor.fetchone() + sql = "UPDATE tile SET status_id = (SELECT id FROM status WHERE name = '" + status[top][second]["status"] + "') WHERE parent_id = '" + str(row[0]) + "'" + cursor.execute(sql) if verbose: print("Imported " + second + " as " + status[top][second]["status"]) + +# Readd trigger +# Trigger for updating secondLevel on tile update +sql = ('CREATE OR REPLACE TRIGGER update_second_level ' +'AFTER UPDATE ON tile ' +'FOR EACH ROW ' +'BEGIN ' + 'IF (SELECT COUNT(status_id) FROM tile WHERE tile.parent_id = NEW.parent_id) = (SELECT COUNT(status_id) FROM tile WHERE tile.parent_id = NEW.parent_id AND status_id = (SELECT id FROM status WHERE name = "packaged")) THEN ' + 'UPDATE secondLevel SET status_id = (SELECT id FROM status WHERE name = "packaged") WHERE id = NEW.parent_id; ' + 'ELSEIF (SELECT COUNT(status_id) FROM tile WHERE tile.parent_id = NEW.parent_id) = (SELECT COUNT(status_id) FROM tile WHERE tile.parent_id = NEW.parent_id AND status_id = (SELECT id FROM status WHERE name = "done")) THEN ' + 'UPDATE secondLevel SET status_id = (SELECT id FROM status WHERE name = "done") WHERE id = NEW.parent_id; ' + 'ELSEIF (SELECT COUNT(status_id) FROM tile WHERE tile.parent_id = NEW.parent_id AND status_id = (SELECT id FROM status WHERE name = "started")) > 0 THEN ' + 'UPDATE secondLevel SET status_id = (SELECT id FROM status WHERE name = "started") WHERE id = NEW.parent_id; ' + 'ELSEIF (SELECT COUNT(status_id) FROM tile WHERE tile.parent_id = NEW.parent_id AND status_id = (SELECT id FROM status WHERE name = "rebuild")) > 0 THEN ' + 'UPDATE secondLevel SET status_id = (SELECT id FROM status WHERE name = "rebuild") WHERE id = NEW.parent_id; ' + 'ELSEIF (SELECT COUNT(status_id) FROM tile WHERE tile.parent_id = NEW.parent_id AND status_id = (SELECT id FROM status WHERE name = "skip")) > 0 THEN ' + 'UPDATE secondLevel SET status_id = (SELECT id FROM status WHERE name = "skip") WHERE id = NEW.parent_id; ' + 'ELSE ' + 'UPDATE secondLevel SET status_id = (SELECT id FROM status WHERE name = "pending") WHERE id = NEW.parent_id; ' + 'END IF; ' +'END; ') +cursor.execute(sql) + db.commit()