diff options
author | George Hazan <george.hazan@gmail.com> | 2015-03-12 22:16:37 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-03-12 22:16:37 +0000 |
commit | 75cff2d80be9ea6c5b946fbe59ef8bc56919f04d (patch) | |
tree | d4c531066101eb5e15453a7d45a7c8cbea67f981 /plugins/Dbx_mdb/src/dbcontacts.cpp | |
parent | 44eb90b35fb7f6be9910d6d5e51bfeed36abe4c8 (diff) |
support for meta merge/split in LMDB
git-svn-id: http://svn.miranda-ng.org/main/trunk@12390 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_mdb/src/dbcontacts.cpp')
-rw-r--r-- | plugins/Dbx_mdb/src/dbcontacts.cpp | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp index 6a3c4dca44..958f48676a 100644 --- a/plugins/Dbx_mdb/src/dbcontacts.cpp +++ b/plugins/Dbx_mdb/src/dbcontacts.cpp @@ -152,23 +152,54 @@ BOOL CDbxMdb::MetaSetDefault(DBCachedContact *cc) return db_set_dw(cc->contactID, META_PROTO, "Default", cc->nDefault);
}
-static int SortEvent(const DBEvent *p1, const DBEvent *p2)
-{
- return (LONG)p1->timestamp - (LONG)p2->timestamp;
-}
+/////////////////////////////////////////////////////////////////////////////////////////
BOOL CDbxMdb::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
{
- mir_cslock lck(m_csDbAccess);
- return -11;
+ DBEventSortingKey keyVal = { 0, 0, ccSub->contactID }, insVal = { 0, 0, ccMeta->contactID };
+ MDB_val key = { sizeof(keyVal), &keyVal }, key2 = { sizeof(insVal), &insVal }, data;
+
+ txn_ptr trnlck(m_pMdbEnv);
+
+ cursor_ptr cursor(trnlck, m_dbEventsSort);
+ mdb_cursor_get(cursor, &key, &data, MDB_SET);
+ while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS) {
+ DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
+ if (pKey->dwContactId != ccSub->contactID)
+ break;
+
+ insVal.ts = pKey->ts;
+ insVal.dwEventId = pKey->dwEventId;
+ mdb_put(trnlck, m_dbEventsSort, &key2, &data, 0);
+ }
+
+ trnlck.commit();
+ return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
BOOL CDbxMdb::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
{
- mir_cslock lck(m_csDbAccess);
- return -11;
+ DBEventSortingKey keyVal = { 0, 0, ccSub->contactID }, delVal = { 0, 0, ccMeta->contactID };
+ MDB_val key = { sizeof(keyVal), &keyVal }, key2 = { sizeof(delVal), &delVal }, data;
+
+ txn_ptr trnlck(m_pMdbEnv);
+
+ cursor_ptr cursor(trnlck, m_dbEventsSort);
+ mdb_cursor_get(cursor, &key, &data, MDB_SET);
+ while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS) {
+ DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
+ if (pKey->dwContactId != ccSub->contactID)
+ break;
+
+ delVal.ts = pKey->ts;
+ delVal.dwEventId = pKey->dwEventId;
+ mdb_del(trnlck, m_dbEventsSort, &key2, &data);
+ }
+
+ trnlck.commit();
+ return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
|