Diff

mod_pubsub_feeds/mod_pubsub_feeds.lua @ 2383:18323c6aa133

mod_pubsub_feeds: Halt feed parsing when we see a node we already know about
author Kim Alvefur <zash@zash.se>
date Sat, 19 Nov 2016 19:38:14 +0100
parent 2382:f159ad7ac18a
child 2384:feba6439b6fb
line wrap: on
line diff
--- a/mod_pubsub_feeds/mod_pubsub_feeds.lua	Sat Nov 19 19:37:21 2016 +0100
+++ b/mod_pubsub_feeds/mod_pubsub_feeds.lua	Sat Nov 19 19:38:14 2016 +0100
@@ -83,13 +83,14 @@
 	for entry in feed:childtags("entry") do
 		table.insert(entries, entry);
 	end
-	local ok = pubsub.service:get_items(node, true);
+	local ok, items = pubsub.service:get_items(node, true);
 	if not ok then
 		local ok, err = pubsub.service:create(node, true);
 		if not ok then
 			module:log("error", "Could not create node %s: %s", node, err);
 			return;
 		end
+		items = {};
 	end
 	for i = #entries, 1, -1 do -- Feeds are usually in reverse order
 		local entry = entries[i];
@@ -112,6 +113,10 @@
 				-- Sigh, no link?
 				id = feed.url .. "#" .. hmac_sha1(feed.url, tostring(entry), true) .. "@" .. dt_datetime(timestamp);
 			end
+			if items[id] then
+				-- Assume that this existing means we've added all new items
+				break;
+			end
 			local xitem = st.stanza("item", { id = id }):add_child(entry);
 			-- TODO Put data from /feed into item/source