Skip to content

Commit

Permalink
Fix high CPU and disk load
Browse files Browse the repository at this point in the history
See jpnurmi#9
Adapted from MAGICCC@dd848d4
  • Loading branch information
BtbN committed Aug 8, 2017
1 parent 360070c commit 50c77e7
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions clientbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
#error The clientbuffer module requires ZNC version 1.7.0 or later.
#endif

class CClientBufferCacheJob : public CTimer
{
public:
CClientBufferCacheJob(CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription)
: CTimer(pModule, uInterval, uCycles, sLabel, sDescription) {}
virtual ~CClientBufferCacheJob() {}

protected:
virtual void RunJob() {
GetModule()->SaveRegistry();
}
};

class CClientBufferMod : public CModule
{
public:
Expand All @@ -37,6 +50,7 @@ class CClientBufferMod : public CModule
AddCommand("AddClient", static_cast<CModCommand::ModCmdFunc>(&CClientBufferMod::OnAddClientCommand), "<identifier>", "Add a client.");
AddCommand("DelClient", static_cast<CModCommand::ModCmdFunc>(&CClientBufferMod::OnDelClientCommand), "<identifier>", "Delete a client.");
AddCommand("ListClients", static_cast<CModCommand::ModCmdFunc>(&CClientBufferMod::OnListClientsCommand), "", "List known clients.");
AddTimer(new CClientBufferCacheJob(this, 60 /* sec */, 0, "ClientBufferCache", "Periodically save ClientBuffer registry to disk"));
}

bool OnLoad(const CString& sArgs, CString& sErrorMsg) override {
Expand Down Expand Up @@ -277,7 +291,7 @@ CModule::EModRet CClientBufferMod::OnPrivBufferPlayMessage(CMessage& Message)
/// Returns true upon success.
bool CClientBufferMod::AddClient(const CString& identifier)
{
return SetNV(identifier, "");
return SetNV(identifier, "", false);
}

/// Remove a client identifier.
Expand All @@ -292,7 +306,7 @@ bool CClientBufferMod::DelClient(const CString& identifier)
}
bool success = true;
for (const CString& key : keys)
success &= DelNV(key);
success &= DelNV(key, false);
return success;
}

Expand Down Expand Up @@ -342,7 +356,7 @@ bool CClientBufferMod::SetTimestamp(const CString& identifier, const CString& ta
{
char timestamp[32];
std::snprintf(timestamp, 32, "%lld.%06ld", (long long)tv.tv_sec, (long)tv.tv_usec);
return SetNV(identifier + "/" + target, timestamp);
return SetNV(identifier + "/" + target, timestamp, false);
}

/// Returns true if the given timestamp is not greater than the "last
Expand Down

0 comments on commit 50c77e7

Please sign in to comment.