360b35a08f
* Fix error messages with ES results * Add lsof for debugging * Add torrents table variable to index sukebei * Use elasticsearch alias for hotswapping index * Increase max open files, increase ES heap size * Add reindex script and reindex triggers We use a table to store the actions happened to the torrents table. When the torrents table is INSERTED/UPDATED/DELETED, the trigger kicks in and an entry is made to the reindex_torrents table. The reindex_nyaapantsu.py script is then used to query the reindex_torrents table and apply the correct reindex action to elasticsearch. The entries are then removed for reindex_torrents table. * Reindex every 5 minutes as cronjob
38 lignes
1,4 Kio
Django/Jinja
38 lignes
1,4 Kio
Django/Jinja
-- Matches the _op_type values from elasticsearch bulk API
|
|
-- https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
|
|
|
|
CREATE TYPE torrents_action AS ENUM ('index', 'delete');
|
|
|
|
CREATE TABLE IF NOT EXISTS reindex_torrents (
|
|
reindex_torrents_id SERIAL,
|
|
torrent_id int,
|
|
action torrents_action
|
|
);
|
|
|
|
CREATE OR REPLACE FUNCTION add_reindex_torrents_action() RETURNS TRIGGER AS $$
|
|
BEGIN
|
|
IF (TG_OP = 'INSERT') THEN
|
|
INSERT INTO reindex_torrents (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');
|
|
RETURN NEW;
|
|
ELSE
|
|
INSERT INTO reindex_torrents (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');
|
|
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
|
|
AFTER INSERT OR UPDATE OR DELETE ON {{ nyaapantsu_torrent_tablename }}
|
|
FOR EACH ROW EXECUTE PROCEDURE add_reindex_torrents_action();
|
|
|
|
-- vim: ft=sql
|