diff options
author | Yorhel <git@yorhel.nl> | 2009-07-18 15:48:32 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2009-07-18 15:48:32 +0200 |
commit | 5cbaaa3616a002a708af785bfa7e0774d50e0751 (patch) | |
tree | f82f4f03b439807b135cce2884e4e95ee71c8722 /util | |
parent | 0a3ebf61cb7ea608f440029c2f138d97fb5a102a (diff) |
Use PostgreSQL's LISTEN/NOTIFY to notify Multi::Anime for new anime
The notify is called from a trigger function, which is called on any
UPDATE or INSERT INTO query of which the lastfetch column is NULL.
This guarantees that anime info in the DB will always be updated, no
matter how its inserted.
Diffstat (limited to 'util')
-rw-r--r-- | util/dump.sql | 15 | ||||
-rw-r--r-- | util/updates/update_2.6.sql | 13 |
2 files changed, 28 insertions, 0 deletions
diff --git a/util/dump.sql b/util/dump.sql index 40347df8..6c08b1b4 100644 --- a/util/dump.sql +++ b/util/dump.sql @@ -700,6 +700,21 @@ $$ LANGUAGE plpgsql; CREATE TRIGGER vn_anime_aid BEFORE INSERT OR UPDATE ON vn_anime FOR EACH ROW EXECUTE PROCEDURE vn_anime_aid(); +-- Send a notify whenever anime info should be fetched +CREATE OR REPLACE FUNCTION anime_fetch_notify() RETURNS trigger AS $$ +BEGIN + IF NEW.lastfetch IS NULL THEN + NOTIFY anime; + END IF; + RETURN NULL; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER anime_fetch_notify AFTER INSERT OR UPDATE ON anime FOR EACH ROW EXECUTE PROCEDURE anime_fetch_notify(); + + + + diff --git a/util/updates/update_2.6.sql b/util/updates/update_2.6.sql index e3516e30..28f82420 100644 --- a/util/updates/update_2.6.sql +++ b/util/updates/update_2.6.sql @@ -48,3 +48,16 @@ $$ LANGUAGE plpgsql; CREATE TRIGGER vn_anime_aid BEFORE INSERT OR UPDATE ON vn_anime FOR EACH ROW EXECUTE PROCEDURE vn_anime_aid(); +-- Send a notify whenever anime info should be fetched +CREATE OR REPLACE FUNCTION anime_fetch_notify() RETURNS trigger AS $$ +BEGIN + IF NEW.lastfetch IS NULL THEN + NOTIFY anime; + END IF; + RETURN NULL; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER anime_fetch_notify AFTER INSERT OR UPDATE ON anime FOR EACH ROW EXECUTE PROCEDURE anime_fetch_notify(); + + |