summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Lang <lang@cosmocode.de>2010-05-04 12:07:35 +0200
committerAdrian Lang <lang@cosmocode.de>2010-05-05 12:23:45 +0200
commit3e0c7aa328ac721b3bcf17822f9ed3659ad93d14 (patch)
tree725d6ccf7970a7c03ce4685f68d6d500915c4a96
parent6b8f02cfe58b224607e5479f8469dde16c3169ac (diff)
downloadrpg-3e0c7aa328ac721b3bcf17822f9ed3659ad93d14.tar.gz
rpg-3e0c7aa328ac721b3bcf17822f9ed3659ad93d14.tar.bz2
Add locking for indexer-based notifications
-rw-r--r--inc/subscription.php28
-rw-r--r--lib/exe/indexer.php4
2 files changed, 32 insertions, 0 deletions
diff --git a/inc/subscription.php b/inc/subscription.php
index e5938d9bd..ce5da4cd4 100644
--- a/inc/subscription.php
+++ b/inc/subscription.php
@@ -9,6 +9,8 @@
* - subscription_set
* - get_info_subscribed
* - subscription_addresslist
+ * - subscription_lock
+ * - subscription_unlock
*
* @author Adrian Lang <lang@cosmocode.de>
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
@@ -37,6 +39,32 @@ function subscription_filename($id) {
}
/**
+ * Lock subscription info for an ID
+ *
+ * @param string $id The target page or namespace, specified by id; Namespaces
+ * are identified by appending a colon.
+ *
+ * @author Adrian Lang <lang@cosmocode.de>
+ */
+function subscription_lock($id) {
+ $lockf = subscription_filename($id) . '.lock';
+ return !file_exists($lockf) && touch($lockf);
+}
+
+/**
+ * Unlock subscription info for an ID
+ *
+ * @param string $id The target page or namespace, specified by id; Namespaces
+ * are identified by appending a colon.
+ *
+ * @author Adrian Lang <lang@cosmocode.de>
+ */
+function subscription_unlock($id) {
+ $lockf = subscription_filename($id) . '.lock';
+ return file_exists($lockf) && unlink($lockf);
+}
+
+/**
* Set subscription information
*
* Allows to set subscription informations for permanent storage in meta files.
diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php
index eb5670005..7e55915f4 100644
--- a/lib/exe/indexer.php
+++ b/lib/exe/indexer.php
@@ -353,6 +353,9 @@ function sendDigest() {
$olduser = $_SERVER['REMOTE_USER'];
foreach($subscriptions as $id => $users) {
+ if (!subscription_lock($id)) {
+ continue;
+ }
foreach($users as $data) {
list($user, $style, $lastupdate) = $data;
$lastupdate = (int) $lastupdate;
@@ -399,6 +402,7 @@ function sendDigest() {
// Update notification time.
subscription_set($user, $id, $style, time(), true);
}
+ subscription_unlock($id);
}
// restore current user info