From f969ef3a76254ef5f53e67f7f94baf5565db6ec5 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 22 Apr 2023 12:33:34 +0300 Subject: Dbx_Sqlite: all this chemistry isn't needed due to m_count initialization in InitContacts() --- plugins/Dbx_sqlite/src/dbevents.cpp | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'plugins/Dbx_sqlite/src/dbevents.cpp') diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp index 4c038a0751..a1722dfc7c 100644 --- a/plugins/Dbx_sqlite/src/dbevents.cpp +++ b/plugins/Dbx_sqlite/src/dbevents.cpp @@ -62,20 +62,7 @@ void CDbxSQLite::UninitEvents() int CDbxSQLite::GetEventCount(MCONTACT hContact) { DBCachedContact *cc = (hContact) ? m_cache->GetCachedContact(hContact) : &m_system; - if (cc == nullptr) - return 0; - - if (cc->HasCount()) - return cc->m_count; - - mir_cslock lock(m_csDbAccess); - sqlite3_stmt *stmt = InitQuery("SELECT COUNT(1) FROM events_srt WHERE contact_id = ? LIMIT 1;", qEvCount); - sqlite3_bind_int64(stmt, 1, hContact); - int rc = sqlite3_step(stmt); - logError(rc, __FILE__, __LINE__); - cc->m_count = (rc != SQLITE_ROW) ? 0 : sqlite3_column_int64(stmt, 0); - sqlite3_reset(stmt); - return cc->m_count; + return (cc == nullptr) ? 0 : cc->m_count; } MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, const DBEVENTINFO *dbei) @@ -159,7 +146,7 @@ MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, const DBEVENTINFO *dbei) logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); - cc->AddEvent(); + cc->m_count++; if (ccSub != nullptr) { stmt = InitQuery(add_event_sort_query, qEvAddSrt); sqlite3_bind_int64(stmt, 1, hDbEvent); @@ -168,7 +155,7 @@ MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, const DBEVENTINFO *dbei) rc = sqlite3_step(stmt); logError(rc, __FILE__, __LINE__); sqlite3_reset(stmt); //is this necessary ? - ccSub->AddEvent(); + ccSub->m_count++; } char *module = m_modules.find((char *)tmp.szModule); @@ -242,8 +229,10 @@ BOOL CDbxSQLite::DeleteEvent(MEVENT hDbEvent) if (rc != SQLITE_DONE) return 1; - if (cc->HasCount()) - cc->m_count--; + cc->m_count--; + if (cc->IsSub()) + if (auto *ccSub = m_cache->GetCachedContact(cc->parentID)) + ccSub->m_count--; lock.unlock(); -- cgit v1.2.3