]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
core_whowas Change the FIFO to be an intrusive list
authorAttila Molnar <attilamolnar@hush.com>
Wed, 9 Jul 2014 13:14:30 +0000 (15:14 +0200)
committerAttila Molnar <attilamolnar@hush.com>
Wed, 9 Jul 2014 13:14:30 +0000 (15:14 +0200)
include/commands/cmd_whowas.h
src/coremods/core_whowas.cpp

index 5c2bb62ee881b056655df6c31924d4f281257400..021e9e3b710f16f7713eb2d9ed3a45f270d5b329 100644 (file)
@@ -34,7 +34,7 @@ namespace WhoWas
 {
        /** Everything known about one nick
         */
-       struct Nick
+       struct Nick : public intrusive_list_node<Nick>
        {
                /** Container where each element has information about one occurrence of this nick
                 */
@@ -56,16 +56,16 @@ namespace WhoWas
                 */
                ~Nick();
        };
+
+       /** Order in which the users were added into the map, used to remove oldest nick
+        */
+       typedef intrusive_list_tail<Nick> FIFO;
 }
 
 /** Sets of users in the whowas system
  */
 typedef std::map<irc::string, WhoWas::Nick*> whowas_users;
 
-/** Sets of time and users in whowas list
- */
-typedef std::deque<std::pair<time_t,irc::string> > whowas_users_fifo;
-
 /** Handle /WHOWAS. These command handlers can be reloaded by the core,
  * and handle basic RFC1459 commands. Commands within modules work
  * the same way, however, they can be fully unloaded, where these
@@ -80,7 +80,7 @@ class CommandWhowas : public Command
 
        /** List of nicknames in the order they were inserted into the map
         */
-       whowas_users_fifo whowas_fifo;
+       WhoWas::FIFO whowas_fifo;
 
   public:
        /** Max number of WhoWas entries per user.
index 53b25eb7ca8e04358e588372b669cc9e85ada5c6..a27eb434179fa04b1b2756d69a7ab80ff74740e6 100644 (file)
@@ -109,19 +109,15 @@ void CommandWhowas::AddToWhoWas(User* user)
                ret.first->second = nick;
 
                // Add this nick to the fifo too
-               whowas_fifo.push_back(std::make_pair(ServerInstance->Time(), ret.first->first));
+               whowas_fifo.push_back(nick);
 
                if (whowas.size() > this->MaxGroups)
                {
                        // Too many nicks, remove the nick which was inserted the longest time ago from both the map and the fifo
-                       whowas_users::iterator it = whowas.find(whowas_fifo.front().second);
-                       if (it != whowas.end())
-                       {
-                               WhoWas::Nick* set = it->second;
-                               delete set;
-                               whowas.erase(it);
-                       }
+                       nick = whowas_fifo.front();
                        whowas_fifo.pop_front();
+                       whowas.erase(nick->nick);
+                       delete nick;
                }
        }
        else
@@ -147,22 +143,19 @@ void CommandWhowas::Prune()
        /* first cut the list to new size (maxgroups) and also prune entries that are timed out. */
        while (!whowas_fifo.empty())
        {
-               if ((whowas_fifo.size() > this->MaxGroups) || (whowas_fifo.front().first < min))
+               WhoWas::Nick* nick = whowas_fifo.front();
+               if ((whowas_fifo.size() > this->MaxGroups) || (nick->addtime < min))
                {
-                       whowas_users::iterator iter = whowas.find(whowas_fifo.front().second);
-
                        /* hopefully redundant integrity check, but added while debugging r6216 */
-                       if (iter == whowas.end())
+                       if (!whowas.erase(nick->nick))
                        {
                                /* this should never happen, if it does maps are corrupt */
                                ServerInstance->Logs->Log("WHOWAS", LOG_DEFAULT, "BUG: Whowas maps got corrupted! (1)");
                                return;
                        }
 
-                       WhoWas::Nick* nick = iter->second;
-                       delete nick;
-                       whowas.erase(iter);
                        whowas_fifo.pop_front();
+                       delete nick;
                }
                else
                        break;