comparison mod_pubsub_feeds/mod_pubsub_feeds.lua @ 5577:e7792188540a

mod_pubsub_feeds: Retrieve only the most recent item to compare Only need one item id. Fetching all items probably caused memory usage peaks.
author Kim Alvefur <zash@zash.se>
date Sun, 25 Jun 2023 19:58:45 +0200
parents c729a38f21b1
children b9821e9a21a2
comparison
equal deleted inserted replaced
5576:c729a38f21b1 5577:e7792188540a
79 end 79 end
80 local entries = {}; 80 local entries = {};
81 for entry in feed:childtags("entry") do 81 for entry in feed:childtags("entry") do
82 table.insert(entries, entry); 82 table.insert(entries, entry);
83 end 83 end
84 local ok, items = pubsub.service:get_items(node, true); 84 local ok, last_id = pubsub.service:get_last_item(node, true);
85 if not ok then 85 if not ok then
86 module:log("error", "PubSub node %q missing: %s", node, items); 86 module:log("error", "PubSub node %q missing: %s", node, last_id);
87 return 87 return
88 end 88 end
89 89
90 local start_from = #entries; 90 local start_from = #entries;
91 for i, entry in ipairs(entries) do 91 for i, entry in ipairs(entries) do
100 return; 100 return;
101 end 101 end
102 entry:text_tag("id", id); 102 entry:text_tag("id", id);
103 end 103 end
104 104
105 if items[id] then 105 if last_id == id then
106 -- This should be the first item that we already have. 106 -- This should be the first item that we already have.
107 start_from = i-1; 107 start_from = i-1;
108 break 108 break
109 end 109 end
110 end 110 end