From 133b7fade64bd0ab9360dd0998b0d5ad170e230b Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 23 Nov 2015 11:42:49 +0100 Subject: [PATCH] core_whowas Purge nicks as soon as they no longer have any entries --- src/coremods/core_whowas.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/coremods/core_whowas.cpp b/src/coremods/core_whowas.cpp index 12ab940dd..79ce94cc9 100644 --- a/src/coremods/core_whowas.cpp +++ b/src/coremods/core_whowas.cpp @@ -76,11 +76,7 @@ const WhoWas::Nick* WhoWas::Manager::FindNick(const std::string& nickname) const whowas_users::const_iterator it = whowas.find(nickname); if (it == whowas.end()) return NULL; - - const Nick* nick = it->second; - if (nick->entries.empty()) - return NULL; - return nick; + return it->second; } WhoWas::Manager::Stats WhoWas::Manager::GetStats() const @@ -153,7 +149,7 @@ void WhoWas::Manager::Prune() } /* Then cut the whowas sets to new size (groupsize) */ - for (whowas_users::iterator i = whowas.begin(); i != whowas.end(); ++i) + for (whowas_users::iterator i = whowas.begin(); i != whowas.end(); ) { WhoWas::Nick::List& list = i->second->entries; while (list.size() > this->GroupSize) @@ -161,6 +157,11 @@ void WhoWas::Manager::Prune() delete list.front(); list.pop_front(); } + + if (list.empty()) + PurgeNick(i++); + else + ++i; } } @@ -168,7 +169,7 @@ void WhoWas::Manager::Prune() void WhoWas::Manager::Maintain() { time_t min = ServerInstance->Time() - this->MaxKeep; - for (whowas_users::iterator i = whowas.begin(); i != whowas.end(); ++i) + for (whowas_users::iterator i = whowas.begin(); i != whowas.end(); ) { WhoWas::Nick::List& list = i->second->entries; while (!list.empty() && list.front()->signon < min) @@ -176,6 +177,11 @@ void WhoWas::Manager::Maintain() delete list.front(); list.pop_front(); } + + if (list.empty()) + PurgeNick(i++); + else + ++i; } } -- 2.39.5