From 3e0c7aa328ac721b3bcf17822f9ed3659ad93d14 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Tue, 4 May 2010 12:07:35 +0200 Subject: Add locking for indexer-based notifications --- inc/subscription.php | 28 ++++++++++++++++++++++++++++ lib/exe/indexer.php | 4 ++++ 2 files changed, 32 insertions(+) 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 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) @@ -36,6 +38,32 @@ function subscription_filename($id) { return metaFN($meta_froot, $meta_fname); } +/** + * 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 + */ +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 + */ +function subscription_unlock($id) { + $lockf = subscription_filename($id) . '.lock'; + return file_exists($lockf) && unlink($lockf); +} + /** * Set subscription information * 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 -- cgit v1.2.3