diff options
Diffstat (limited to 'plugins/Dbx_mdb/src')
-rw-r--r-- | plugins/Dbx_mdb/src/dbcontacts.cpp | 79 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbintf.h | 11 |
2 files changed, 57 insertions, 33 deletions
diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp index 05d235c4e3..ede6270b5f 100644 --- a/plugins/Dbx_mdb/src/dbcontacts.cpp +++ b/plugins/Dbx_mdb/src/dbcontacts.cpp @@ -154,31 +154,46 @@ BOOL CDbxMdb::MetaSetDefault(DBCachedContact *cc) /////////////////////////////////////////////////////////////////////////////////////////
-BOOL CDbxMdb::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
+void CDbxMdb::GatherContactHistory(MCONTACT hContact, LIST<EventItem> &list)
{
- DBEventSortingKey keyVal = { 0, 0, ccSub->contactID }, insVal = { 0, 0, ccMeta->contactID };
- MDB_val key = { sizeof(keyVal), &keyVal }, key2 = { sizeof(insVal), &insVal }, data;
+ DBEventSortingKey keyVal = { 0, 0, hContact };
+ MDB_val key = { sizeof(keyVal), &keyVal }, data;
+
+ txn_ptr trnlck(m_pMdbEnv, true);
+ 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 != hContact)
+ return;
+
+ list.insert(new EventItem(pKey->ts, pKey->dwEventId));
+ }
+}
- 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;
+BOOL CDbxMdb::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
+{
+ LIST<EventItem> list(10000);
+ GatherContactHistory(ccSub->contactID, list);
- insVal.ts = pKey->ts;
- insVal.dwEventId = pKey->dwEventId;
- mdb_put(trnlck, m_dbEventsSort, &key2, &data, 0);
+ for (int i = 0; i < list.getCount(); i++) {
+ EventItem *EI = list[i];
- ccMeta->dbc.dwEventCount++;
+ for (;; Remap()) {
+ txn_ptr trnlck(m_pMdbEnv);
+ DBEventSortingKey insVal = { EI->eventId, EI->ts, ccMeta->contactID };
+ MDB_val key = { sizeof(insVal), &insVal }, data = { 1, "" };
+ mdb_put(trnlck, m_dbEventsSort, &key, &data, 0);
+ if (trnlck.commit())
+ break;
}
+ ccMeta->dbc.dwEventCount++;
+ delete EI;
}
MDB_val keyc = { sizeof(int), &ccMeta->contactID }, datac = { sizeof(ccMeta->dbc), &ccMeta->dbc };
+ txn_ptr trnlck(m_pMdbEnv);
mdb_put(trnlck, m_dbContacts, &keyc, &datac, 0);
-
trnlck.commit();
return 0;
}
@@ -187,29 +202,27 @@ BOOL CDbxMdb::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) BOOL CDbxMdb::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
{
- 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;
+ LIST<EventItem> list(10000);
+ GatherContactHistory(ccSub->contactID, list);
- delVal.ts = pKey->ts;
- delVal.dwEventId = pKey->dwEventId;
- mdb_del(trnlck, m_dbEventsSort, &key2, &data);
+ for (int i = 0; i < list.getCount(); i++) {
+ EventItem *EI = list[i];
- ccMeta->dbc.dwEventCount--;
+ for (;; Remap()) {
+ txn_ptr trnlck(m_pMdbEnv);
+ DBEventSortingKey insVal = { EI->eventId, EI->ts, ccMeta->contactID };
+ MDB_val key = { sizeof(insVal), &insVal }, data = { 1, "" };
+ mdb_del(trnlck, m_dbEventsSort, &key, &data);
+ if (trnlck.commit())
+ break;
}
+ ccMeta->dbc.dwEventCount--;
+ delete EI;
}
-
+
MDB_val keyc = { sizeof(int), &ccMeta->contactID }, datac = { sizeof(ccMeta->dbc), &ccMeta->dbc };
+ txn_ptr trnlck(m_pMdbEnv);
mdb_put(trnlck, m_dbContacts, &keyc, &datac, 0);
-
trnlck.commit();
return 0;
}
diff --git a/plugins/Dbx_mdb/src/dbintf.h b/plugins/Dbx_mdb/src/dbintf.h index b97df6c787..d4b8a587a5 100644 --- a/plugins/Dbx_mdb/src/dbintf.h +++ b/plugins/Dbx_mdb/src/dbintf.h @@ -117,6 +117,16 @@ struct DBCachedContact : public DBCachedContactBase DBContact dbc;
};
+struct EventItem
+{
+ __forceinline EventItem(int _ts, DWORD _id) :
+ ts(_ts), eventId(_id)
+ {}
+
+ int ts;
+ DWORD eventId;
+};
+
struct CDbxMdb : public MIDatabase, public MIDatabaseChecker, public MZeroedObject
{
CDbxMdb(const TCHAR *tszFileName, int mode);
@@ -238,6 +248,7 @@ protected: int m_contactCount, m_dwMaxContactId;
int WipeContactHistory(DBContact *dbc);
+ void GatherContactHistory(MCONTACT hContact, LIST<EventItem> &items);
////////////////////////////////////////////////////////////////////////////
// events
|