mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-03 23:04:08 +01:00
add in-memory cacheing of messageless-connname/hid combos.
This commit is contained in:
parent
657d0d2b1f
commit
c212c0e367
2 changed files with 65 additions and 8 deletions
|
@ -981,6 +981,8 @@ void
|
||||||
DBMgr::StoreMessage( const char* const connName, int hid,
|
DBMgr::StoreMessage( const char* const connName, int hid,
|
||||||
const uint8_t* buf, int len )
|
const uint8_t* buf, int len )
|
||||||
{
|
{
|
||||||
|
clearHasNoMessages( connName, hid );
|
||||||
|
|
||||||
DevIDRelay devID = getDevID( connName, hid );
|
DevIDRelay devID = getDevID( connName, hid );
|
||||||
if ( DEVID_NONE == devID ) {
|
if ( DEVID_NONE == devID ) {
|
||||||
logf( XW_LOGERROR, "%s: warning: devid not found for connName=%s, "
|
logf( XW_LOGERROR, "%s: warning: devid not found for connName=%s, "
|
||||||
|
@ -1105,9 +1107,15 @@ void
|
||||||
DBMgr::GetStoredMessages( const char* const connName, HostID hid,
|
DBMgr::GetStoredMessages( const char* const connName, HostID hid,
|
||||||
vector<DBMgr::MsgInfo>& msgs )
|
vector<DBMgr::MsgInfo>& msgs )
|
||||||
{
|
{
|
||||||
StrWPF query;
|
if ( !hasNoMessages( connName, hid ) ) {
|
||||||
query.printf( "hid = %d AND connname = '%s'", hid, connName );
|
StrWPF query;
|
||||||
storedMessagesImpl( query, msgs, false );
|
query.printf( "hid = %d AND connname = '%s'", hid, connName );
|
||||||
|
storedMessagesImpl( query, msgs, false );
|
||||||
|
|
||||||
|
if ( 0 == msgs.size() ) {
|
||||||
|
setHasNoMessages( connName, hid );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1182,10 +1190,53 @@ DBMgr::getCountWhere( const char* table, string& test )
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DBMgr::formatKey( StrWPF& key, const char* const connName, HostID hid )
|
||||||
|
{
|
||||||
|
key.printf( "%s:%d", connName, hid );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
DBMgr::hasNoMessages( const char* const connName, HostID hid )
|
||||||
|
{
|
||||||
|
StrWPF key;
|
||||||
|
formatKey( key, connName, hid );
|
||||||
|
MutexLock ml( &m_haveNoMessagesMutex );
|
||||||
|
bool result = m_haveNoMessagesConnname.find(key) != m_haveNoMessagesConnname.end();
|
||||||
|
logf( XW_LOGINFO, "%s(key=%s)=>%d", __func__, key.c_str(), result );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DBMgr::setHasNoMessages( const char* const connName, HostID hid )
|
||||||
|
{
|
||||||
|
StrWPF key;
|
||||||
|
formatKey( key, connName, hid );
|
||||||
|
logf( XW_LOGINFO, "%s(key=%s)", __func__, key.c_str() );
|
||||||
|
{
|
||||||
|
MutexLock ml( &m_haveNoMessagesMutex );
|
||||||
|
m_haveNoMessagesConnname.insert( key );
|
||||||
|
}
|
||||||
|
assert( hasNoMessages( connName, hid ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DBMgr::clearHasNoMessages( const char* const connName, HostID hid )
|
||||||
|
{
|
||||||
|
StrWPF key;
|
||||||
|
formatKey( key, connName, hid );
|
||||||
|
logf( XW_LOGINFO, "%s(key=%s)", __func__, key.c_str() );
|
||||||
|
{
|
||||||
|
MutexLock ml( &m_haveNoMessagesMutex );
|
||||||
|
m_haveNoMessagesConnname.erase( key );
|
||||||
|
}
|
||||||
|
assert( !hasNoMessages( connName, hid ) );
|
||||||
|
}
|
||||||
|
|
||||||
bool DBMgr::hasNoMessages( DevIDRelay devid )
|
bool DBMgr::hasNoMessages( DevIDRelay devid )
|
||||||
{
|
{
|
||||||
MutexLock ml( &m_haveNoMessagesMutex );
|
MutexLock ml( &m_haveNoMessagesMutex );
|
||||||
bool result = m_haveNoMessages.find(devid) != m_haveNoMessages.end();
|
bool result = m_haveNoMessagesDevID.find(devid) != m_haveNoMessagesDevID.end();
|
||||||
logf( XW_LOGINFO, "%s(devid=%d)=>%d", __func__, devid, result );
|
logf( XW_LOGINFO, "%s(devid=%d)=>%d", __func__, devid, result );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1195,7 +1246,7 @@ void DBMgr::setHasNoMessages( DevIDRelay devid )
|
||||||
logf( XW_LOGINFO, "%s(devid=%d)", __func__, devid );
|
logf( XW_LOGINFO, "%s(devid=%d)", __func__, devid );
|
||||||
{
|
{
|
||||||
MutexLock ml( &m_haveNoMessagesMutex );
|
MutexLock ml( &m_haveNoMessagesMutex );
|
||||||
m_haveNoMessages.insert( devid );
|
m_haveNoMessagesDevID.insert( devid );
|
||||||
}
|
}
|
||||||
assert( hasNoMessages( devid ) );
|
assert( hasNoMessages( devid ) );
|
||||||
}
|
}
|
||||||
|
@ -1205,7 +1256,7 @@ void DBMgr::clearHasNoMessages( DevIDRelay devid )
|
||||||
logf( XW_LOGINFO, "%s(devid=%d)", __func__, devid );
|
logf( XW_LOGINFO, "%s(devid=%d)", __func__, devid );
|
||||||
{
|
{
|
||||||
MutexLock ml( &m_haveNoMessagesMutex );
|
MutexLock ml( &m_haveNoMessagesMutex );
|
||||||
m_haveNoMessages.erase( devid );
|
m_haveNoMessagesDevID.erase( devid );
|
||||||
}
|
}
|
||||||
assert( !hasNoMessages( devid ) );
|
assert( !hasNoMessages( devid ) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
#include "strwpf.h"
|
||||||
#include "xwrelay.h"
|
#include "xwrelay.h"
|
||||||
#include "xwrelay_priv.h"
|
#include "xwrelay_priv.h"
|
||||||
#include "devid.h"
|
#include "devid.h"
|
||||||
|
@ -165,6 +166,11 @@ class DBMgr {
|
||||||
PGconn* getThreadConn( void );
|
PGconn* getThreadConn( void );
|
||||||
void clearThreadConn();
|
void clearThreadConn();
|
||||||
|
|
||||||
|
bool hasNoMessages( const char* const connName, HostID hid );
|
||||||
|
void setHasNoMessages( const char* const connName, HostID hid );
|
||||||
|
void clearHasNoMessages( const char* const connName, HostID hid );
|
||||||
|
void formatKey( StrWPF& key, const char* const connName, HostID hid );
|
||||||
|
|
||||||
bool hasNoMessages( DevIDRelay devid );
|
bool hasNoMessages( DevIDRelay devid );
|
||||||
void setHasNoMessages( DevIDRelay devid );
|
void setHasNoMessages( DevIDRelay devid );
|
||||||
void clearHasNoMessages( DevIDRelay devid );
|
void clearHasNoMessages( DevIDRelay devid );
|
||||||
|
@ -174,8 +180,8 @@ class DBMgr {
|
||||||
bool m_useB64;
|
bool m_useB64;
|
||||||
|
|
||||||
pthread_mutex_t m_haveNoMessagesMutex;
|
pthread_mutex_t m_haveNoMessagesMutex;
|
||||||
set<DevIDRelay> m_haveNoMessages;
|
set<DevIDRelay> m_haveNoMessagesDevID;
|
||||||
|
set<StrWPF> m_haveNoMessagesConnname;
|
||||||
}; /* DBMgr */
|
}; /* DBMgr */
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue