summaryrefslogtreecommitdiff
path: root/plugins/Dbx_kyoto
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-04-05 12:47:33 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-04-05 12:47:33 +0000
commitb16ff48e46b50ecedbc7ae448cf91c8915fedd3b (patch)
tree41dc25b6b9d385845b8dc9fc119d47e2abd9bb0d /plugins/Dbx_kyoto
parent8717c665cc0c324e3732a3350571069d9aecf539 (diff)
minor speed improvement
git-svn-id: http://svn.miranda-ng.org/main/trunk@12608 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_kyoto')
-rw-r--r--plugins/Dbx_kyoto/src/dbevents.cpp73
-rw-r--r--plugins/Dbx_kyoto/src/dbintf.cpp4
-rw-r--r--plugins/Dbx_kyoto/src/dbintf.h2
3 files changed, 47 insertions, 32 deletions
diff --git a/plugins/Dbx_kyoto/src/dbevents.cpp b/plugins/Dbx_kyoto/src/dbevents.cpp
index e1b3cf3206..13a652e15e 100644
--- a/plugins/Dbx_kyoto/src/dbevents.cpp
+++ b/plugins/Dbx_kyoto/src/dbevents.cpp
@@ -195,18 +195,20 @@ STDMETHODIMP_(BOOL) CDbxKyoto::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
void CDbxKyoto::FindNextUnread(DBCachedContact *cc, DBEventSortingKey &key2)
{
key2.dwEventId++;
-
- cursor_ptr cursor(m_dbEventsSort);
- cursor->jump((LPCSTR)&key2, sizeof(key2));
- while(cursor->step()) {
- size_t size;
- const char *pRec;
- delete[] cursor->get(&size, &pRec, &size);
- DBEvent *dbe = (DBEvent*)pRec;
- if (!dbe->markedRead()) {
- cc->dbc.dwFirstUnread = key2.dwEventId;
- cc->dbc.tsFirstUnread = key2.ts;
- return;
+ {
+ mir_cslock lck(m_csDbAccess);
+
+ m_evCursor->jump((LPCSTR)&key2, sizeof(key2));
+ while (m_evCursor->step()) {
+ size_t size;
+ const char *pRec;
+ delete[] m_evCursor->get(&size, &pRec, &size);
+ DBEvent *dbe = (DBEvent*)pRec;
+ if (!dbe->markedRead()) {
+ cc->dbc.dwFirstUnread = key2.dwEventId;
+ cc->dbc.tsFirstUnread = key2.ts;
+ return;
+ }
}
}
@@ -259,12 +261,13 @@ STDMETHODIMP_(MCONTACT) CDbxKyoto::GetEventContact(MEVENT hDbEvent)
STDMETHODIMP_(MEVENT) CDbxKyoto::FindFirstEvent(MCONTACT contactID)
{
- DBEventSortingKey keyVal = { contactID, 0, 0 };
- cursor_ptr cursor(m_dbEventsSort);
- cursor->jump((LPCSTR)&keyVal, sizeof(keyVal));
-
size_t size;
- DBEventSortingKey *pKey = (DBEventSortingKey*)cursor->get_key(&size);
+ DBEventSortingKey keyVal = { contactID, 0, 0 }, *pKey;
+ {
+ mir_cslock lck(m_csDbAccess);
+ m_evCursor->jump((LPCSTR)&keyVal, sizeof(keyVal));
+ pKey = (DBEventSortingKey*)m_evCursor->get_key(&size);
+ }
if (pKey == NULL)
return m_evLast = 0;
@@ -282,12 +285,14 @@ STDMETHODIMP_(MEVENT) CDbxKyoto::FindFirstUnreadEvent(MCONTACT contactID)
STDMETHODIMP_(MEVENT) CDbxKyoto::FindLastEvent(MCONTACT contactID)
{
- DBEventSortingKey keyVal = { contactID, 0xFFFFFFFF, 0xFFFFFFFF };
- cursor_ptr cursor(m_dbEventsSort);
- cursor->jump_back((LPCSTR)&keyVal, sizeof(keyVal));
-
size_t size;
- DBEventSortingKey *pKey = (DBEventSortingKey*)cursor->get_key(&size);
+ DBEventSortingKey keyVal = { contactID, 0xFFFFFFFF, 0xFFFFFFFF }, *pKey;
+ {
+ mir_cslock lck(m_csDbAccess);
+ m_evCursor->jump_back((LPCSTR)&keyVal, sizeof(keyVal));
+ pKey = (DBEventSortingKey*)m_evCursor->get_key(&size);
+ }
+
if (pKey == NULL)
return m_evLast = 0;
@@ -311,12 +316,14 @@ STDMETHODIMP_(MEVENT) CDbxKyoto::FindNextEvent(MCONTACT contactID, MEVENT hDbEve
}
else ts = m_tsLast;
- DBEventSortingKey keyVal = { contactID, ts, hDbEvent+1 };
- cursor_ptr cursor(m_dbEventsSort);
- cursor->jump((LPCSTR)&keyVal, sizeof(keyVal));
-
size_t size;
- DBEventSortingKey *pKey = (DBEventSortingKey*)cursor->get_key(&size);
+ DBEventSortingKey keyVal = { contactID, ts, hDbEvent + 1 }, *pKey;
+ {
+ mir_cslock lck(m_csDbAccess);
+ m_evCursor->jump((LPCSTR)&keyVal, sizeof(keyVal));
+ pKey = (DBEventSortingKey*)m_evCursor->get_key(&size);
+ }
+
if (pKey == NULL)
return m_evLast = 0;
@@ -340,12 +347,14 @@ STDMETHODIMP_(MEVENT) CDbxKyoto::FindPrevEvent(MCONTACT contactID, MEVENT hDbEve
}
else ts = m_tsLast;
- DBEventSortingKey keyVal = { contactID, ts, hDbEvent-1 };
- cursor_ptr cursor(m_dbEventsSort);
- cursor->jump_back((LPCSTR)&keyVal, sizeof(keyVal));
-
size_t size;
- DBEventSortingKey *pKey = (DBEventSortingKey*)cursor->get_key(&size);
+ DBEventSortingKey keyVal = { contactID, ts, hDbEvent - 1 }, *pKey;
+ {
+ mir_cslock lck(m_csDbAccess);
+ cursor->jump_back((LPCSTR)&keyVal, sizeof(keyVal));
+ pKey = (DBEventSortingKey*)m_evCursor->get_key(&size);
+ }
+
if (pKey == NULL)
return m_evLast = 0;
diff --git a/plugins/Dbx_kyoto/src/dbintf.cpp b/plugins/Dbx_kyoto/src/dbintf.cpp
index bd43f0fa7d..6a4af0a824 100644
--- a/plugins/Dbx_kyoto/src/dbintf.cpp
+++ b/plugins/Dbx_kyoto/src/dbintf.cpp
@@ -97,6 +97,8 @@ CDbxKyoto::CDbxKyoto(const TCHAR *tszFileName, int iMode) :
CDbxKyoto::~CDbxKyoto()
{
+ delete m_evCursor;
+
m_dbContacts.close();
m_dbModules.close();
m_dbEvents.close();
@@ -172,6 +174,8 @@ int CDbxKyoto::Load(bool bSkipInit)
m_dbContacts.set((LPCSTR)&keyVal, sizeof(keyVal), (LPCSTR)&dbc, sizeof(dbc));
}
+ m_evCursor = m_dbEventsSort.cursor();
+
if (InitModuleNames()) return EGROKPRF_CANTREAD;
if (InitCrypt()) return EGROKPRF_CANTREAD;
diff --git a/plugins/Dbx_kyoto/src/dbintf.h b/plugins/Dbx_kyoto/src/dbintf.h
index 9e75bd2804..c46a99e903 100644
--- a/plugins/Dbx_kyoto/src/dbintf.h
+++ b/plugins/Dbx_kyoto/src/dbintf.h
@@ -246,6 +246,8 @@ protected:
CTable m_dbEvents, m_dbEventsSort;
DWORD m_dwMaxEventId, m_tsLast;
MEVENT m_evLast;
+
+ TreeDB::Cursor *m_evCursor;
void FindNextUnread(DBCachedContact *cc, DBEventSortingKey &key2);