Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0

Fix reindex script (allow both table) (#942)

Cette révision appartient à :
tomleb 2017-06-05 22:46:51 -04:00 révisé par ewhal
Parent 7bb452a477
révision f3c8515263
2 fichiers modifiés avec 9 ajouts et 9 suppressions

Voir le fichier

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

Voir le fichier

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