+ /* 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 = ServerInstance->whowas.size();
+ /* iterate whowas_fifo oldest first */
+ whowas_users_fifo::iterator iter, safeiter;
+ for (iter = ServerInstance->whowas_fifo.begin(); iter != ServerInstance->whowas_fifo.end(); iter++)
+ {
+ /** 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;
+ if (n->size())
+ {
+ while (n->begin() != n->end())
+ {
+ WhoWasGroup *a = *(n->begin());
+ DELETE(a);
+ n->erase(n->begin());
+ }
+ }
+ ServerInstance->whowas.erase(iter->second);
+ /* use a safe iter copy for erase and set the orig iter old valid ref by decrementing it */
+ safeiter = iter;
+ --iter;
+ ServerInstance->whowas_fifo.erase(safeiter);
+ }
+ 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 = n->size();
+ while (n->begin() != n->end() && nickcount > groupsize)
+ {
+ WhoWasGroup *a = *(n->begin());
+ DELETE(a);
+ n->erase(n->begin());
+ nickcount--;
+ }
+ }
+ }
+ groupcount--;
+ }
+ }