summaryrefslogtreecommitdiff
path: root/plugins/Dbx_sqlite
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-04-22 12:33:34 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-04-22 12:33:34 +0300
commitf969ef3a76254ef5f53e67f7f94baf5565db6ec5 (patch)
tree4dff8e97fa608d8c76cdc59a99e3f722b54a7596 /plugins/Dbx_sqlite
parent7dab3935aeffca7eedea4c964a8d14754da4c852 (diff)
Dbx_Sqlite: all this chemistry isn't needed due to m_count initialization in InitContacts()
Diffstat (limited to 'plugins/Dbx_sqlite')
-rw-r--r--plugins/Dbx_sqlite/src/dbevents.cpp25
-rw-r--r--plugins/Dbx_sqlite/src/dbintf.h17
2 files changed, 9 insertions, 33 deletions
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();
diff --git a/plugins/Dbx_sqlite/src/dbintf.h b/plugins/Dbx_sqlite/src/dbintf.h
index 83071ae90c..9e9716f153 100644
--- a/plugins/Dbx_sqlite/src/dbintf.h
+++ b/plugins/Dbx_sqlite/src/dbintf.h
@@ -13,20 +13,7 @@ struct CQuery
struct DBCachedContact : public DBCachedContactBase
{
- int32_t m_count;
-
- DBCachedContact() :
- m_count(-1)
- {}
-
- __forceinline void AddEvent()
- {
- m_count = HasCount() ? m_count + 1 : 1;
- }
-
- __forceinline bool HasCount() const {
- return m_count > -1;
- }
+ int32_t m_count = 0;
};
struct CDbxSQLiteEventCursor : public DB::EventCursor
@@ -92,7 +79,7 @@ class CDbxSQLite : public MDatabaseCommon, public MIDatabaseChecker, public MZer
LIST<char> m_modules;
void InitEvents();
void UninitEvents();
- CQuery qEvCount, qEvAdd, qEvDel, qEvEdit, qEvBlobSize, qEvGet, qEvGetFlags, qEvSetFlags, qEvGetContact, qEvGetContact2;
+ CQuery qEvAdd, qEvDel, qEvEdit, qEvBlobSize, qEvGet, qEvGetFlags, qEvSetFlags, qEvGetContact, qEvGetContact2;
CQuery qEvFindFirst, qEvFindNext, qEvFindLast, qEvFindPrev, qEvFindUnread, qEvAddSrt, qEvDelSrt, qEvMetaSplit, qEvMetaMerge;
CQuery qEvGetById, qEvUpdateId, qEvSetJson;
int DeleteEventMain(MEVENT);