Changeset

766:1184fe8ebb21

mod_pubsub_hub: Try to choose time until the next periodic check in a sane way
author Kim Alvefur <zash@zash.se>
date Thu, 02 Aug 2012 00:25:24 +0200
parents 765:82d292e4f30f
children 767:e5667f1da6bf
files mod_pubsub_hub/mod_pubsub_hub.lua
diffstat 1 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mod_pubsub_hub/mod_pubsub_hub.lua	Wed Aug 01 17:14:03 2012 +0200
+++ b/mod_pubsub_hub/mod_pubsub_hub.lua	Thu Aug 02 00:25:24 2012 +0200
@@ -144,15 +144,14 @@
 local function periodic()
 	local now = time();
 	local next_check = now + max_lease;
-	local purge = false
+	local purge = false;
 	for topic, callbacks in pairs(subs_by_topic) do
 		for callback, subscription in pairs(callbacks) do
 			if subscription.mode == "subscribed" then
 				if subscription.expires < now then
 					-- Subscription has expired, drop it.
-					purge = true
-				end
-				if subscription.expires < now + min_lease  then
+					purge = true;
+				elseif subscription.expires < now + min_lease  then
 					-- Subscription set to expire soon, re-confirm it.
 					local challenge = uuid();
 					local callback_url = callback .. (callback:match("%?") and "&" or "?") .. formencode{
@@ -168,7 +167,7 @@
 						end
 					end);
 				else
-					next_check = m_min(next_check, now - subscription.expires)
+					next_check = m_min(next_check, subscription.expires);
 				end
 			end
 		end
@@ -180,10 +179,11 @@
 					new_callbacks[callback] = subscription;
 				end
 			end
-			subs_by_topic[topic] = new_callbacks
+			subs_by_topic[topic] = new_callbacks;
+			purge = false;
 		end
 	end
-	return m_max(next_check - min_lease, min_lease);
+	return now - m_max(next_check - min_lease, min_lease);
 end
 
 local function on_notify(subscription, content)