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/src/dbevents.cpp | |
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/src/dbevents.cpp')
-rw-r--r-- | plugins/Dbx_mdb/src/dbevents.cpp | 65 |
1 files changed, 45 insertions, 20 deletions
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;
|