diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2016-03-07 17:52:10 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2016-03-07 17:52:10 +0000 |
commit | 96dee8f7351ce6137ff864088639c96ffde2ec42 (patch) | |
tree | 38ecc073fc49022490414c9eedaaae3cd0ad5713 /plugins/Dbx_mdb | |
parent | a704113576cb1f75463c26140e3aad20487ded33 (diff) |
dbx_lmdb: more fixes for metacontacts
git-svn-id: http://svn.miranda-ng.org/main/trunk@16442 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_mdb')
-rw-r--r-- | plugins/Dbx_mdb/src/dbcontacts.cpp | 2 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbevents.cpp | 65 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbintf.cpp | 20 |
3 files changed, 50 insertions, 37 deletions
diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp index e6789abeb4..e8f72bc9c3 100644 --- a/plugins/Dbx_mdb/src/dbcontacts.cpp +++ b/plugins/Dbx_mdb/src/dbcontacts.cpp @@ -235,7 +235,7 @@ BOOL CDbxMdb::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) delete EI;
}
- MDB_val keyc = { sizeof(int), &ccMeta->contactID }, datac = { sizeof(ccMeta->dbc), &ccMeta->dbc };
+ MDB_val keyc = { sizeof(MCONTACT), &ccMeta->contactID }, datac = { sizeof(ccMeta->dbc), &ccMeta->dbc };
for (;; Remap())
{
diff --git a/plugins/Dbx_mdb/src/dbevents.cpp b/plugins/Dbx_mdb/src/dbevents.cpp index 7824b19b83..a69b57a5bf 100644 --- a/plugins/Dbx_mdb/src/dbevents.cpp +++ b/plugins/Dbx_mdb/src/dbevents.cpp @@ -86,7 +86,10 @@ STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) DWORD dwEventId = ++m_dwMaxEventId;
- for (cc->Snapshot();; cc->Revert(), Remap()) {
+ const auto Snapshot = [&]() { cc->Snapshot(); if (ccSub) ccSub->Snapshot(); };
+ const auto Revert = [&]() { cc->Revert(); if (ccSub) ccSub->Revert(); };
+
+ for (Snapshot();; Revert(), Remap()) {
txn_ptr txn(m_pMdbEnv);
MDB_val key = { sizeof(int), &dwEventId }, data = { sizeof(DBEvent) + dbe.cbBlob, NULL };
@@ -132,40 +135,62 @@ STDMETHODIMP_(MEVENT) CDbxMdb::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) STDMETHODIMP_(BOOL) CDbxMdb::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent)
{
- DBCachedContact *cc = m_cache->GetCachedContact(contactID);
+ DBCachedContact *cc = m_cache->GetCachedContact(contactID), *cc2 = nullptr;
if (cc == NULL || cc->dbc.dwEventCount == 0)
return 1;
mir_cslockfull lck(m_csDbAccess);
- for (cc->Snapshot();; cc->Revert(), Remap())
+ const DBEvent *dbe = nullptr;
{
- txn_ptr txn(m_pMdbEnv);
+ txn_ptr_ro txn(m_txn);
MDB_val key = { sizeof(MEVENT), &hDbEvent }, data;
- MDB_CHECK(mdb_get(txn, m_dbEvents, &key, &data), 1);
+ if (mdb_get(txn, m_dbEvents, &key, &data) != MDB_SUCCESS || data.mv_data == nullptr)
+ return 1;
+ dbe = (const DBEvent*)data.mv_data;
+ }
- DBEvent *dbe = (DBEvent*)data.mv_data;
- DWORD dwSavedContact = dbe->contactID;
+ if (contactID != dbe->contactID)
+ {
+ cc2 = m_cache->GetCachedContact(dbe->contactID);
+ }
+
+ const auto Snapshot = [&]() { cc->Snapshot(); if (cc2) cc2->Snapshot(); };
+ const auto Revert = [&]() { cc->Revert(); if (cc2) cc2->Revert(); };
+
+ for (Snapshot();; Revert(), Remap())
+ {
DBEventSortingKey key2 = { hDbEvent, dbe->timestamp, contactID };
- // remove a sorting key
- key.mv_size = sizeof(key2); key.mv_data = &key2;
+ txn_ptr txn(m_pMdbEnv);
+ MDB_val key = { sizeof(key2), &key2 }, data;
+
MDB_CHECK(mdb_del(txn, m_dbEventsSort, &key, &data), 1)
- // remove a sub's history entry too
- if (contactID != dwSavedContact) {
- key2.dwContactId = dwSavedContact;
- MDB_CHECK(mdb_del(txn, m_dbEventsSort, &key, &data), 1);
+ {
+ key.mv_size = sizeof(MCONTACT); key.mv_data = &contactID;
+ cc->dbc.dwEventCount--;
+ if (cc->dbc.dwFirstUnread == hDbEvent)
+ FindNextUnread(txn, cc, key2);
+
+ data.mv_size = sizeof(DBContact); data.mv_data = &cc->dbc;
+ MDB_CHECK(mdb_put(txn, m_dbContacts, &key, &data, 0), 1);
}
- // update a contact
- key.mv_size = sizeof(MCONTACT); key.mv_data = &contactID;
- cc->dbc.dwEventCount--;
- if (cc->dbc.dwFirstUnread == hDbEvent)
- FindNextUnread(txn, cc, key2);
+ if (cc2)
+ {
+ key2.dwContactId = dbe->contactID;
+ MDB_CHECK(mdb_del(txn, m_dbEventsSort, &key, &data), 1);
+
+ key.mv_size = sizeof(MCONTACT); key.mv_data = &contactID;
+ cc2->dbc.dwEventCount--;
+ if (cc2->dbc.dwFirstUnread == hDbEvent)
+ FindNextUnread(txn, cc2, key2);
- data.mv_size = sizeof(DBContact); data.mv_data = &cc->dbc;
- MDB_CHECK(mdb_put(txn, m_dbContacts, &key, &data, 0), 1);
+ data.mv_size = sizeof(DBContact); data.mv_data = &cc2->dbc;
+ MDB_CHECK(mdb_put(txn, m_dbContacts, &key, &data, 0), 1);
+
+ }
// remove a event
key.mv_size = sizeof(MEVENT); key.mv_data = &hDbEvent;
diff --git a/plugins/Dbx_mdb/src/dbintf.cpp b/plugins/Dbx_mdb/src/dbintf.cpp index db41a585b0..3c12201951 100644 --- a/plugins/Dbx_mdb/src/dbintf.cpp +++ b/plugins/Dbx_mdb/src/dbintf.cpp @@ -23,18 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h"
-/*#define CMP_DWORDS_K(x, y, f) { if(x->f != y->f) return (x->f<y->f)?-1:1; }
-
-static int EventsComparator(const MDB_val *v1, const MDB_val *v2)
-{
- const DBEventSortingKey *k1 = (DBEventSortingKey *)v1->mv_data;
- const DBEventSortingKey *k2 = (DBEventSortingKey *)v2->mv_data;
- CMP_DWORDS_K(k1, k2, dwContactId);
- CMP_DWORDS_K(k1, k2, ts);
- CMP_DWORDS_K(k1, k2, dwEventId);
- return 0;
-}*/
-
static int ModCompare(const ModuleName *mn1, const ModuleName *mn2)
{
return strcmp(mn1->name, mn2->name);
@@ -108,18 +96,18 @@ int CDbxMdb::Load(bool bSkipInit) mdb_dbi_open(trnlck, "eventsrt", defFlags | MDB_INTEGERKEY, &m_dbEventsSort);
mdb_dbi_open(trnlck, "settings", defFlags, &m_dbSettings);
- //mdb_set_compare(trnlck, m_dbEventsSort, EventsComparator);
-
DWORD keyVal = 1;
MDB_val key = { sizeof(DWORD), &keyVal }, data;
- if (mdb_get(trnlck, m_dbGlobal, &key, &data) == MDB_SUCCESS) {
+ if (mdb_get(trnlck, m_dbGlobal, &key, &data) == MDB_SUCCESS)
+ {
DBHeader *hdr = (DBHeader*)data.mv_data;
if (hdr->dwSignature != DBHEADER_SIGNATURE)
DatabaseCorruption(NULL);
memcpy(&m_header, data.mv_data, sizeof(m_header));
}
- else {
+ else
+ {
m_header.dwSignature = DBHEADER_SIGNATURE;
m_header.dwVersion = 1;
data.mv_data = &m_header; data.mv_size = sizeof(m_header);
|