From 78b13a92fb3bbc7d7ae3cc31e84a99758e392d4d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 18 Jan 2015 21:14:32 +0000 Subject: bunch of small fixes, optimizations and improvements git-svn-id: http://svn.miranda-ng.org/main/trunk@11874 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dbx_mdb/src/dbcontacts.cpp | 42 +++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'plugins/Dbx_mdb/src/dbcontacts.cpp') diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp index 14267ab9ff..094cb0331e 100644 --- a/plugins/Dbx_mdb/src/dbcontacts.cpp +++ b/plugins/Dbx_mdb/src/dbcontacts.cpp @@ -58,6 +58,10 @@ STDMETHODIMP_(MCONTACT) CDbxMdb::FindFirstContact(const char *szProto) if (cc == NULL) return NULL; + if (cc->contactID == 0) + if ((cc = m_cache->GetNextContact(0)) == NULL) + return NULL; + if (!szProto || CheckProto(cc, szProto)) return cc->contactID; @@ -92,7 +96,7 @@ STDMETHODIMP_(LONG) CDbxMdb::DeleteContact(MCONTACT contactID) // delete mir_cslock lck(m_csDbAccess); - MDB_val key = { sizeof(DWORD), &contactID }; + MDB_val key = { sizeof(MCONTACT), &contactID }; for (;; Remap()) { txn_ptr trnlck(m_pMdbEnv); @@ -106,15 +110,15 @@ STDMETHODIMP_(LONG) CDbxMdb::DeleteContact(MCONTACT contactID) STDMETHODIMP_(MCONTACT) CDbxMdb::AddContact() { DWORD dwContactId; - - DBContact dbc = { 0 }; - dbc.signature = DBCONTACT_SIGNATURE; { mir_cslock lck(m_csDbAccess); dwContactId = m_dwMaxContactId++; - MDB_val key = { sizeof(DWORD), &dwContactId }; - MDB_val data = { sizeof(DBContact), &dbc }; + DBCachedContact *cc = m_cache->AddContactToCache(dwContactId); + cc->dbc.dwSignature = DBCONTACT_SIGNATURE; + + MDB_val key = { sizeof(MCONTACT), &dwContactId }; + MDB_val data = { sizeof(cc->dbc), &cc->dbc }; for (;; Remap()) { txn_ptr trnlck(m_pMdbEnv); @@ -122,8 +126,6 @@ STDMETHODIMP_(MCONTACT) CDbxMdb::AddContact() if (trnlck.commit()) break; } - - m_cache->AddContactToCache(dwContactId); } NotifyEventHooks(hContactAddedEvent, dwContactId, 0); @@ -169,6 +171,21 @@ BOOL CDbxMdb::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) return -11; } +///////////////////////////////////////////////////////////////////////////////////////// + +void DBCachedContact::Advance(DWORD id, DBEvent &dbe) +{ + dbc.dwEventCount++; + + if (dbe.flags & (DBEF_READ | DBEF_SENT)) + return; + + if (dbe.timestamp < dbc.tsFirstUnread || dbc.tsFirstUnread == 0) { + dbc.tsFirstUnread = dbe.timestamp; + dbc.dwFirstUnread = id; + } +} + ///////////////////////////////////////////////////////////////////////////////////////// // initial cycle to fill the contacts' cache @@ -184,13 +201,14 @@ void CDbxMdb::FillContacts() MDB_val key, data; while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == 0) { DBContact *dbc = (DBContact*)data.mv_data; - if (dbc->signature != DBCONTACT_SIGNATURE) + if (dbc->dwSignature != DBCONTACT_SIGNATURE) DatabaseCorruption(NULL); DBCachedContact *cc = m_cache->AddContactToCache(*(DWORD*)key.mv_data); - cc->dwEventCount = dbc->eventCount; - cc->dwFirstUnread = dbc->dwFirstUnread; - cc->tsFirstUnread = dbc->tsFirstUnread; + cc->dbc.dwSignature = DBCONTACT_SIGNATURE; + cc->dbc.dwEventCount = dbc->dwEventCount; + cc->dbc.dwFirstUnread = dbc->dwFirstUnread; + cc->dbc.tsFirstUnread = dbc->tsFirstUnread; arContacts.insert(cc); } } -- cgit v1.2.3