From f3c85152634e6ca91a5f6434eac8191df75b3939 Mon Sep 17 00:00:00 2001 From: tomleb Date: Mon, 5 Jun 2017 22:46:51 -0400 Subject: [PATCH] Fix reindex script (allow both table) (#942) --- .../elasticsearch/files/reindex_nyaapantsu.py | 2 +- .../templates/reindex_triggers.sql.j2 | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/deploy/ansible/roles/elasticsearch/files/reindex_nyaapantsu.py b/deploy/ansible/roles/elasticsearch/files/reindex_nyaapantsu.py index fa07bce4..037a0cd6 100644 --- a/deploy/ansible/roles/elasticsearch/files/reindex_nyaapantsu.py +++ b/deploy/ansible/roles/elasticsearch/files/reindex_nyaapantsu.py @@ -60,7 +60,7 @@ while fetches: } new_action['_source'] = doc select_cur.close() - delete_cur.execute('DELETE FROM reindex_torrents WHERE id = {reindex_id}'.format(reindex_id=reindex_id)) + delete_cur.execute('DELETE FROM reindex_{torrent_tablename} WHERE reindex_torrents_id = {reindex_id}'.format(reindex_id=reindex_id,torrent_tablename=torrent_tablename)) actions.append(new_action) pgconn.commit() # Commit the deletes transaction delete_cur.close() diff --git a/deploy/ansible/roles/elasticsearch/templates/reindex_triggers.sql.j2 b/deploy/ansible/roles/elasticsearch/templates/reindex_triggers.sql.j2 index 8f144756..04f93407 100644 --- a/deploy/ansible/roles/elasticsearch/templates/reindex_triggers.sql.j2 +++ b/deploy/ansible/roles/elasticsearch/templates/reindex_triggers.sql.j2 @@ -9,30 +9,30 @@ CREATE TABLE IF NOT EXISTS reindex_{{ nyaapantsu_torrent_tablename }} ( action torrents_action ); -CREATE OR REPLACE FUNCTION add_reindex_torrents_action() RETURNS TRIGGER AS $$ +CREATE OR REPLACE FUNCTION add_reindex_{{ nyaapantsu_torrent_tablename }}_action() RETURNS TRIGGER AS $$ BEGIN IF (TG_OP = 'INSERT') THEN - INSERT INTO reindex_torrents (torrent_id, action) VALUES (NEW.torrent_id, 'index'); + INSERT INTO reindex_{{ nyaapantsu_torrent_tablename }} (torrent_id, action) VALUES (NEW.torrent_id, 'index'); RETURN NEW; ELSIF (TG_OP = 'UPDATE') THEN IF (NEW.deleted_at IS NOT NULL) THEN - INSERT INTO reindex_torrents (torrent_id, action) VALUES (OLD.torrent_id, 'delete'); + INSERT INTO reindex_{{ nyaapantsu_torrent_tablename }} (torrent_id, action) VALUES (OLD.torrent_id, 'delete'); RETURN NEW; ELSE - INSERT INTO reindex_torrents (torrent_id, action) VALUES (NEW.torrent_id, 'index'); + INSERT INTO reindex_{{ nyaapantsu_torrent_tablename }} (torrent_id, action) VALUES (NEW.torrent_id, 'index'); RETURN NEW; END IF; ELSIF (TG_OP = 'DELETE') THEN - INSERT INTO reindex_torrents (torrent_id, action) VALUES (OLD.torrent_id, 'delete'); + INSERT INTO reindex_{{ nyaapantsu_torrent_tablename }} (torrent_id, action) VALUES (OLD.torrent_id, 'delete'); RETURN OLD; END IF; RETURN NULL; -- result is ignored since this is an AFTER trigger END; $$ LANGUAGE plpgsql; -DROP TRIGGER IF EXISTS trigger_reindex_torrents ON {{ nyaapantsu_torrent_tablename }}; -CREATE TRIGGER trigger_reindex_torrents +DROP TRIGGER IF EXISTS trigger_reindex_{{ nyaapantsu_torrent_tablename }} ON {{ nyaapantsu_torrent_tablename }}; +CREATE TRIGGER trigger_reindex_{{ nyaapantsu_torrent_tablename }} AFTER INSERT OR UPDATE OR DELETE ON {{ nyaapantsu_torrent_tablename }} - FOR EACH ROW EXECUTE PROCEDURE add_reindex_torrents_action(); + FOR EACH ROW EXECUTE PROCEDURE add_reindex_{{ nyaapantsu_torrent_tablename }}_action(); -- vim: ft=sql