summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-07-18 15:48:32 +0200
committerYorhel <git@yorhel.nl>2009-07-18 15:48:32 +0200
commit5cbaaa3616a002a708af785bfa7e0774d50e0751 (patch)
treef82f4f03b439807b135cce2884e4e95ee71c8722
parent0a3ebf61cb7ea608f440029c2f138d97fb5a102a (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.
-rw-r--r--lib/Multi/Anime.pm6
-rw-r--r--lib/VNDB/Handler/VNEdit.pm1
-rw-r--r--util/dump.sql15
-rw-r--r--util/updates/update_2.6.sql13
4 files changed, 33 insertions, 2 deletions
diff --git a/lib/Multi/Anime.pm b/lib/Multi/Anime.pm
index b1d5ed3e..bc01d26e 100644
--- a/lib/Multi/Anime.pm
+++ b/lib/Multi/Anime.pm
@@ -79,6 +79,9 @@ sub _start {
$_[KERNEL]->alias_set('anime');
$_[KERNEL]->sig(shutdown => 'shutdown');
+ # listen for 'anime' notifies
+ $_[KERNEL]->post(pg => listen => anime => 'check_anime');
+
# init the UDP 'connection'
$_[HEAP]{w} = POE::Wheel::UDP->new(
(map { $_ => $_[HEAP]{$_} } qw| LocalAddr LocalPort PeerAddr PeerPort |),
@@ -93,6 +96,7 @@ sub _start {
sub shutdown {
undef $_[HEAP]{w};
+ $_[KERNEL]->post(pg => unlisten => 'anime');
$_[KERNEL]->delay('check_anime');
$_[KERNEL]->delay('nextcmd');
$_[KERNEL]->delay('receivepacket');
@@ -109,7 +113,7 @@ sub check_anime {
sub fetch_anime { # num, res
# nothing to do, check again later
- return $_[KERNEL]->delay('check_anime', $_[HEAP]{check_delay}) if !$_[ARG0] == 0;
+ return $_[KERNEL]->delay('check_anime', $_[HEAP]{check_delay}) if $_[ARG0] == 0;
# otherwise, fetch info (if we aren't doing so already)
return if $_[HEAP]{aid};
diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm
index f0f12e88..8e4de7ec 100644
--- a/lib/VNDB/Handler/VNEdit.pm
+++ b/lib/VNDB/Handler/VNEdit.pm
@@ -92,7 +92,6 @@ sub edit {
}
$self->multiCmd("ircnotify v$nvid.$nrev");
- $self->multiCmd('anime') if $vid && $frm->{anime} ne $b4{anime} || !$vid && $frm->{anime};
return $self->resRedirect("/v$nvid.$nrev", 'post');
}
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();
+
+