summaryrefslogtreecommitdiff
path: root/src/nickcore.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-02-13 17:42:01 -0500
committerAdam <Adam@anope.org>2013-02-14 01:20:18 -0500
commit9e544a6443117861c3d6406e435043f1cf0f7099 (patch)
treee7449fb01e377576e8a09f386117d2c251de0596 /src/nickcore.cpp
parent225b7c38c127fbc6aac6724012f71c9483a4da77 (diff)
Store what channels have references to accounts in NickCore to prevent having to iterate over all channels and then all access entries when nicks expire or from nickserv/alist
Diffstat (limited to 'src/nickcore.cpp')
-rw-r--r--src/nickcore.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/nickcore.cpp b/src/nickcore.cpp
index 7dda6da5c..f92d4739c 100644
--- a/src/nickcore.cpp
+++ b/src/nickcore.cpp
@@ -17,7 +17,7 @@
Serialize::Checker<nickcore_map> NickCoreList("NickCore");
-NickCore::NickCore(const Anope::string &coredisplay) : Serializable("NickCore"), aliases("NickAlias")
+NickCore::NickCore(const Anope::string &coredisplay) : Serializable("NickCore"), chanaccess("ChannelInfo"), aliases("NickAlias")
{
if (coredisplay.empty())
throw CoreException("Empty display passed to NickCore constructor");
@@ -44,6 +44,9 @@ NickCore::~NickCore()
{
FOREACH_MOD(I_OnDelCore, OnDelCore(this));
+ if (!this->chanaccess->empty())
+ Log(LOG_DEBUG) << "Non-empty chanaccess list in destructor!";
+
for (std::list<User *>::iterator it = this->users.begin(); it != this->users.end();)
{
User *user = *it++;
@@ -253,6 +256,25 @@ void NickCore::ClearCert()
this->cert.clear();
}
+void NickCore::AddChannelReference(ChannelInfo *ci)
+{
+ ++(*this->chanaccess)[ci];
+}
+
+void NickCore::RemoveChannelReference(ChannelInfo *ci)
+{
+ int& i = (*this->chanaccess)[ci];
+ if (--i <= 0)
+ this->chanaccess->erase(ci);
+}
+
+void NickCore::GetChannelReferences(std::deque<ChannelInfo *> &queue)
+{
+ queue.clear();
+ for (std::map<ChannelInfo *, int>::iterator it = this->chanaccess->begin(), it_end = this->chanaccess->end(); it != it_end; ++it)
+ queue.push_back(it->first);
+}
+
NickCore* NickCore::Find(const Anope::string &nick)
{
nickcore_map::const_iterator it = NickCoreList->find(nick);