summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdb/src/dbintf.cpp
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2016-02-18 12:32:59 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2016-02-18 12:32:59 +0000
commit2868202cb6260735157346833a4cf6326772011d (patch)
tree8bd251c1f657b3057975afee34055eba2c66f458 /plugins/Dbx_mdb/src/dbintf.cpp
parent73a0b84498501c1e2907f1cdc5f222f1f400edfd (diff)
dbx_lmdb: speed optimization
git-svn-id: http://svn.miranda-ng.org/main/trunk@16301 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_mdb/src/dbintf.cpp')
-rw-r--r--plugins/Dbx_mdb/src/dbintf.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/plugins/Dbx_mdb/src/dbintf.cpp b/plugins/Dbx_mdb/src/dbintf.cpp
index 503746369e..b7c0c81572 100644
--- a/plugins/Dbx_mdb/src/dbintf.cpp
+++ b/plugins/Dbx_mdb/src/dbintf.cpp
@@ -23,6 +23,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
+#define CMP_UINT32(A,B) if (A != B) return (A < B) ? -1 : 1;
+
+static int MDB_CompareEvents(const MDB_val *v1, const MDB_val *v2)
+{
+ DBEventSortingKey *k1 = static_cast<DBEventSortingKey*>(v1->mv_data);
+ DBEventSortingKey *k2 = static_cast<DBEventSortingKey*>(v2->mv_data);
+ CMP_UINT32(k1->dwContactId, k2->dwContactId);
+ CMP_UINT32(k1->ts, k2->ts);
+ CMP_UINT32(k1->dwEventId, k2->dwEventId);
+ return 0;
+}
+
static int ModCompare(const ModuleName *mn1, const ModuleName *mn2)
{
return strcmp(mn1->name, mn2->name);
@@ -85,11 +97,12 @@ CDbxMdb::~CDbxMdb()
int CDbxMdb::Load(bool bSkipInit)
{
- if (!Remap())
+ if (!Map())
return EGROKPRF_CANTREAD;
if (!bSkipInit) {
txn_ptr trnlck(m_pMdbEnv);
+
mdb_open(trnlck, "global", MDB_CREATE | MDB_INTEGERKEY, &m_dbGlobal);
mdb_open(trnlck, "contacts", MDB_CREATE | MDB_INTEGERKEY, &m_dbContacts);
mdb_open(trnlck, "modules", MDB_CREATE | MDB_INTEGERKEY, &m_dbModules);
@@ -97,6 +110,8 @@ int CDbxMdb::Load(bool bSkipInit)
mdb_open(trnlck, "eventsrt", MDB_CREATE | MDB_INTEGERKEY, &m_dbEventsSort);
mdb_open(trnlck, "settings", MDB_CREATE, &m_dbSettings);
+ //mdb_set_compare(trnlck, m_dbEventsSort, MDB_CompareEvents);
+
DWORD keyVal = 1;
MDB_val key = { sizeof(DWORD), &keyVal }, data;
if (mdb_get(trnlck, m_dbGlobal, &key, &data) == MDB_SUCCESS) {
@@ -146,7 +161,7 @@ int CDbxMdb::Load(bool bSkipInit)
int CDbxMdb::Create(void)
{
m_dwFileSize = 0;
- return (Remap()) ? 0 : EGROKPRF_CANTREAD;
+ return (Map()) ? 0 : EGROKPRF_CANTREAD;
}
int CDbxMdb::Check(void)
@@ -182,7 +197,7 @@ STDMETHODIMP_(void) CDbxMdb::SetCacheSafetyMode(BOOL bIsSet)
m_safetyMode = bIsSet != 0;
}
-bool CDbxMdb::Remap()
+bool CDbxMdb::Map()
{
m_dwFileSize += 0x100000;
mdb_env_set_mapsize(m_pMdbEnv, m_dwFileSize);
@@ -195,6 +210,13 @@ bool CDbxMdb::Remap()
return mdb_env_open(m_pMdbEnv, _T2A(m_tszProfileName), mode, 0664) == MDB_SUCCESS;
}
+bool CDbxMdb::Remap()
+{
+ mir_cslock lck(m_csDbAccess);
+ m_dwFileSize += 0x100000;
+ return mdb_env_set_mapsize(m_pMdbEnv, m_dwFileSize) == MDB_SUCCESS;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
static DWORD DatabaseCorrupted = 0;