diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-04-04 19:23:16 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-04-04 19:23:16 +0200 |
commit | bb3aa2fb37071f48a5312df8688c0a6990644fbb (patch) | |
tree | e48e8f3d6bac2f608e9ad18b6af88fc0a712e310 /src | |
parent | 7b823baf68b7512a36ac513f3c6b0d920776fa59 (diff) |
Stop recreating hashmaps every hour, move garbage collection code related to local users to UserManager
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/cmd_rehash.cpp | 1 | ||||
-rw-r--r-- | src/inspircd.cpp | 37 | ||||
-rw-r--r-- | src/server.cpp | 1 | ||||
-rw-r--r-- | src/usermanager.cpp | 11 |
4 files changed, 12 insertions, 38 deletions
diff --git a/src/commands/cmd_rehash.cpp b/src/commands/cmd_rehash.cpp index abf0b7876..1ad96d794 100644 --- a/src/commands/cmd_rehash.cpp +++ b/src/commands/cmd_rehash.cpp @@ -88,7 +88,6 @@ CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, Use /* Don't do anything with the logs here -- logs are restarted * after the config thread has completed. */ - ServerInstance->RehashUsersAndChans(); FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect()); diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 9ab7b9dbe..c34908378 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -191,41 +191,6 @@ void InspIRCd::ResetMaxBans() i->second->ResetMaxBans(); } -/** Because hash_map doesn't free its buckets when we delete items, we occasionally - * recreate the hash to free them up. - * We do this by copying the entries from the old hash to a new hash, causing all - * empty buckets to be weeded out of the hash. - * Since this is quite expensive, it's not done very often. - */ -void InspIRCd::RehashUsersAndChans() -{ - user_hash* old_users = Users->clientlist; - Users->clientlist = new user_hash; - for (user_hash::const_iterator n = old_users->begin(); n != old_users->end(); n++) - Users->clientlist->insert(*n); - delete old_users; - - user_hash* old_uuid = Users->uuidlist; - Users->uuidlist = new user_hash; - for (user_hash::const_iterator n = old_uuid->begin(); n != old_uuid->end(); n++) - Users->uuidlist->insert(*n); - delete old_uuid; - - chan_hash* old_chans = chanlist; - chanlist = new chan_hash; - for (chan_hash::const_iterator n = old_chans->begin(); n != old_chans->end(); n++) - chanlist->insert(*n); - delete old_chans; - - // Reset the already_sent IDs so we don't wrap it around and drop a message - LocalUser::already_sent_id = 0; - for (LocalUserList::const_iterator i = Users->local_users.begin(); i != Users->local_users.end(); i++) - { - (**i).already_sent = 0; - (**i).RemoveExpiredInvites(); - } -} - void InspIRCd::SetSignals() { #ifndef _WIN32 @@ -818,7 +783,7 @@ int InspIRCd::Run() if ((TIME.tv_sec % 3600) == 0) { - this->RehashUsersAndChans(); + Users->GarbageCollect(); FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect()); } diff --git a/src/server.cpp b/src/server.cpp index 4741f942d..691ab3842 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -59,7 +59,6 @@ void InspIRCd::Exit(int status) void RehashHandler::Call(const std::string &reason) { ServerInstance->SNO->WriteToSnoMask('a', "Rehashing config file %s %s",ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()), reason.c_str()); - ServerInstance->RehashUsersAndChans(); FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect()); if (!ServerInstance->ConfigThread) { diff --git a/src/usermanager.cpp b/src/usermanager.cpp index 58cbb7e5b..2d9c3f281 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -389,3 +389,14 @@ int UserManager::ModeCount(const char mode) } return c; } + +void UserManager::GarbageCollect() +{ + // Reset the already_sent IDs so we don't wrap it around and drop a message + LocalUser::already_sent_id = 0; + for (LocalUserList::const_iterator i = this->local_users.begin(); i != this->local_users.end(); i++) + { + (**i).already_sent = 0; + (**i).RemoveExpiredInvites(); + } +} |