summaryrefslogtreecommitdiff
path: root/src/users.cpp
diff options
context:
space:
mode:
authorpeavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7>2006-11-13 08:15:35 +0000
committerpeavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7>2006-11-13 08:15:35 +0000
commitb9552dc5beae210e5e8a626dcf636da43c962365 (patch)
treea66c2f342fa5c19f128add86731ccd1eb54bd6df /src/users.cpp
parent5fa3fd9274a2cb3b3cff82e85713983579de2a13 (diff)
Fix PruneWhoWas to actually work right on rehash. Add debug output to whowas. More code comments to whowas.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5734 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/users.cpp')
-rw-r--r--src/users.cpp39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/users.cpp b/src/users.cpp
index f3278186b..184eef8ef 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -861,7 +861,7 @@ namespace irc
free(gecos);
}
- /* every hour, run this function which removes all entries over 3 days */
+ /* every hour, run this function which removes all entries older than Config->WhoWasMaxKeep */
void MaintainWhoWas(InspIRCd* ServerInstance, time_t t)
{
for (whowas_users::iterator iter = ServerInstance->whowas.begin(); iter != ServerInstance->whowas.end(); iter++)
@@ -881,15 +881,19 @@ namespace irc
/* on rehash, refactor maps according to new conf values */
void PruneWhoWas(InspIRCd* ServerInstance, time_t t)
{
+ /* config values */
int groupsize = ServerInstance->Config->WhoWasGroupSize;
int maxgroups = ServerInstance->Config->WhoWasMaxGroups;
int maxkeep = ServerInstance->Config->WhoWasMaxKeep;
- int groupcount = 0;
+ int groupcount = ServerInstance->whowas.size();
+ /* iterate whowas_fifo oldest first */
for (whowas_users_fifo::iterator iter = ServerInstance->whowas_fifo.begin(); iter != ServerInstance->whowas_fifo.end(); iter++)
{
- groupcount++;
-
+ /** prune all groups that has expired due to new maxkeep time and
+ * also any group number higher than new maxgroups. The oldest are
+ * removed first due to iteration over whowas_fifo
+ */
if (groupcount > maxgroups || iter->first < t - maxkeep)
{
whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second;
@@ -906,21 +910,21 @@ namespace irc
ServerInstance->whowas_fifo.erase(iter->first);
}
else {
+ /* also trim individual groupsizes in case groupsize should have been lowered */
whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second;
if (n->size())
{
- int nickcount = 0;
- while (n->begin() != n->end())
+ int nickcount = n->size();
+ while (n->begin() != n->end() && nickcount > groupsize)
{
- nickcount++;
- if (nickcount > groupsize){
- WhoWasGroup *a = *(n->begin());
- DELETE(a);
- n->erase(n->begin());
- }
+ WhoWasGroup *a = *(n->begin());
+ DELETE(a);
+ n->erase(n->begin());
+ nickcount--;
}
}
}
+ groupcount--;
}
}
};
@@ -929,6 +933,12 @@ namespace irc
/* adds or updates an entry in the whowas list */
void userrec::AddToWhoWas()
{
+ /* if whowas disabled */
+ if (ServerInstance->Config->WhoWasGroupSize == 0 || ServerInstance->Config->WhoWasMaxGroups == 0)
+ {
+ return;
+ }
+
irc::whowas::whowas_users::iterator iter = ServerInstance->whowas.find(this->nick);
ServerInstance->Log(DEBUG,"Add to whowas lists");
@@ -943,6 +953,7 @@ void userrec::AddToWhoWas()
ServerInstance->whowas_fifo[ServerInstance->Time()] = this->nick;
if ((int)(ServerInstance->whowas.size()) > ServerInstance->Config->WhoWasMaxGroups)
{
+ ServerInstance->Log(DEBUG,"Maxgroups of %d reached deleting oldest group '%s'",ServerInstance->Config->WhoWasMaxGroups, ServerInstance->whowas_fifo.begin()->second.c_str());
ServerInstance->whowas.erase(ServerInstance->whowas_fifo.begin()->second);
ServerInstance->whowas_fifo.erase(ServerInstance->whowas_fifo.begin());
}
@@ -953,9 +964,9 @@ void userrec::AddToWhoWas()
ServerInstance->Log(DEBUG,"Using existing whowas group for %s",this->nick);
- if ((int)(group->size()) > ServerInstance->Config->WhoWasMaxGroups)
+ if ((int)(group->size()) >= ServerInstance->Config->WhoWasGroupSize)
{
- ServerInstance->Log(DEBUG,"Trimming existing group to ten entries for %s",this->nick);
+ ServerInstance->Log(DEBUG,"Trimming existing group '%s' to %d entries",this->nick, ServerInstance->Config->WhoWasGroupSize);
irc::whowas::WhoWasGroup *a = (irc::whowas::WhoWasGroup*)*(group->begin());
DELETE(a);
group->pop_front();