Run import without trigger as it slows things down

Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
fly 2020-08-27 11:06:58 +00:00
parent 83ca0c66c7
commit f2bb5d6654

View file

@ -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()