# HG changeset patch # User JC Brand # Date 1489494956 0 # Node ID 7c3a1688e385fe2b649addefc4a92400ffe7249a # Parent c814c667d4d15da369e2949cc538bc56e6c7331d Purge the roster from RAM when the user logs off. Also.. the `download` flag was being checked for, but never set, causing the roster to be fetched even if it was cached. diff -r c814c667d4d1 -r 7c3a1688e385 mod_http_roster_admin/mod_http_roster_admin.lua --- a/mod_http_roster_admin/mod_http_roster_admin.lua Tue Mar 14 04:20:02 2017 +0100 +++ b/mod_http_roster_admin/mod_http_roster_admin.lua Tue Mar 14 12:35:56 2017 +0000 @@ -22,6 +22,9 @@ local st = require "util.stanza"; local array = require "util.array"; +local bare_sessions = prosody.bare_sessions; +local storagemanager = require "core.storagemanager"; + local host = module.host; local sessions = hosts[host].sessions; @@ -213,13 +216,14 @@ -- Are we the first callback to handle the downloaded roster? local first = roster[false].downloaded == nil; - if first then -- Fill out new roster for jid, friend in pairs(friends) do roster[jid] = friend_to_roster_item(friend); end end + + roster[false].downloaded = true; -- Send full roster to client session.send(build_roster_reply(stanza, roster)); @@ -290,6 +294,14 @@ return true; end +module:hook("resource-unbind", function (event) + local user_bare_jid = event.session.username.."@"..event.session.host; + if not bare_sessions[user_bare_jid] then -- User went offline + -- We don't need this user's info cached anymore, clear it. + module:log("debug", "Purging the roster for %s", user_bare_jid); + storagemanager.open(event.session.host, "roster", "keyval").store[event.session.username] = nil; + end +end); module:provides("http", { route = {