From 720783e4a86c5a89592847c79b4ab932f9ff6879 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 13 Mar 2014 19:42:54 +0000 Subject: fix for db_event_count in subs git-svn-id: http://svn.miranda-ng.org/main/trunk@8598 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Db3x_mmap/src/dbcontacts.cpp | 1 - plugins/Db3x_mmap/src/dbevents.cpp | 16 ++++++++++++++++ plugins/Db3x_mmap/src/dbtool/contactchain.cpp | 6 +++--- 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'plugins/Db3x_mmap') diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp index bdc60424f6..7d8fc5a143 100644 --- a/plugins/Db3x_mmap/src/dbcontacts.cpp +++ b/plugins/Db3x_mmap/src/dbcontacts.cpp @@ -289,7 +289,6 @@ BOOL CDb3Mmap::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) } // remove any traces of history from sub - dbSub->eventCount = 0; dbSub->ofsFirstEvent = dbSub->ofsLastEvent = dbSub->ofsFirstUnread = dbSub->tsFirstUnread = 0; } __except (EXCEPTION_EXECUTE_HANDLER) diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp index 7513348cad..7be737b1ba 100644 --- a/plugins/Db3x_mmap/src/dbevents.cpp +++ b/plugins/Db3x_mmap/src/dbevents.cpp @@ -46,12 +46,14 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) dbe.cbBlob = dbei->cbBlob; BYTE *pBlob = dbei->pBlob; + DBCachedContact *ccSub = NULL; if (contactID != 0) { DBCachedContact *cc = m_cache->GetCachedContact(contactID); if (cc == NULL) return NULL; if (cc->IsSub()) { + ccSub = cc; // set default sub to the event's source db_mc_setDefault(cc->parentID, contactID); contactID = cc->parentID; // and add an event to a metahistory @@ -137,6 +139,11 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) } else neednotify = m_safetyMode; + if (ccSub != NULL) { + DBContact *pSub = (DBContact*)DBRead(ccSub->dwDriverData, sizeof(DBContact), NULL); + pSub->eventCount++; + } + DBWrite(ofsContact, &dbc, sizeof(DBContact)); DBWrite(ofsNew, &dbe, offsetof(DBEvent, blob)); DBWrite(ofsNew + offsetof(DBEvent, blob), pBlob, dbe.cbBlob); @@ -224,6 +231,15 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteEvent(MCONTACT contactID, HANDLE hDbEvent) //decrement event count dbc.eventCount--; DBWrite(ofsContact, &dbc, sizeof(DBContact)); + + // also update a sub + if (dbc.dwContactID != contactID) { + DBCachedContact *cc = m_cache->GetCachedContact(dbc.dwContactID); + DBContact *pSub = (DBContact*)DBRead(cc->dwDriverData, sizeof(DBContact), NULL); + if (pSub->eventCount > 0) + pSub->eventCount--; + } + DBFlush(0); return 0; } diff --git a/plugins/Db3x_mmap/src/dbtool/contactchain.cpp b/plugins/Db3x_mmap/src/dbtool/contactchain.cpp index 979071fad4..f1ba3ebe61 100644 --- a/plugins/Db3x_mmap/src/dbtool/contactchain.cpp +++ b/plugins/Db3x_mmap/src/dbtool/contactchain.cpp @@ -70,7 +70,7 @@ LBL_FinishUp: contactCount++; phase++; first = 1; - //fall thru + // fall thru case 1: ret = WorkSettingsChain(ofsDestThis, &dbc, first); if (ret == ERROR_NO_MORE_ITEMS) { @@ -79,7 +79,7 @@ LBL_FinishUp: else if (ret) return ret; else break; - //fall thru + // fall thru case 2: ret = WorkEventChain(ofsDestThis, &dbc, first); if (ret == ERROR_NO_MORE_ITEMS) { @@ -88,7 +88,7 @@ LBL_FinishUp: else if (ret) return ret; else break; - //fall thru + // fall thru case 3: if (WriteSegment(ofsDestThis, &dbc, sizeof(DBContact)) == WS_ERROR) return ERROR_HANDLE_DISK_FULL; -- cgit v1.2.3