summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-01-10 16:28:20 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-01-10 16:28:20 +0300
commit589c9b56e11e57adae8ef94eaeef8e32b8c460e2 (patch)
tree48b6df86362f8db8227d2e71d0a3722c752547c3
parent5f1bfb3384c581024c3c8b80cde6742f3a126cea (diff)
fixes #3276 (Очень медленное добавление и удаление событий из базы)
-rw-r--r--plugins/Dbx_sqlite/src/dbcheck.cpp5
-rw-r--r--plugins/Dbx_sqlite/src/dbevents.cpp25
-rw-r--r--plugins/Dbx_sqlite/src/dbintf.h4
-rw-r--r--plugins/Dbx_sqlite/src/version.h2
4 files changed, 27 insertions, 9 deletions
diff --git a/plugins/Dbx_sqlite/src/dbcheck.cpp b/plugins/Dbx_sqlite/src/dbcheck.cpp
index 6a75178cf8..658d48cce6 100644
--- a/plugins/Dbx_sqlite/src/dbcheck.cpp
+++ b/plugins/Dbx_sqlite/src/dbcheck.cpp
@@ -28,7 +28,7 @@ int CDbxSQLite::CheckPhase1()
int CDbxSQLite::CheckPhase2()
{
sqlite3_stmt *pQuery;
- int rc = sqlite3_prepare_v2(m_db, "SELECT id, contact_id FROM events_srt WHERE id NOT IN (SELECT id FROM events)", -1, &pQuery, nullptr);
+ int rc = sqlite3_prepare_v2(m_db, "SELECT id, contact_id, timestamp FROM events_srt WHERE id NOT IN (SELECT id FROM events)", -1, &pQuery, nullptr);
logError(rc, __FILE__, __LINE__);
if (rc)
return rc;
@@ -36,8 +36,9 @@ int CDbxSQLite::CheckPhase2()
while (sqlite3_step(pQuery) == SQLITE_ROW) {
MEVENT hDbEvent = sqlite3_column_int(pQuery, 0);
MCONTACT hContact = sqlite3_column_int(pQuery, 1);
+ uint32_t ts = sqlite3_column_int(pQuery, 2);
- DeleteEventSrt(hDbEvent);
+ DeleteEventSrt(hDbEvent, hContact, ts);
cb->pfnAddLogMessage(STATUS_ERROR, CMStringW(FORMAT, TranslateT("Orphaned sorting event with wrong event ID %d:%08X, deleting"), hContact, hDbEvent));
}
diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp
index bf8959c977..f4a4618c2e 100644
--- a/plugins/Dbx_sqlite/src/dbevents.cpp
+++ b/plugins/Dbx_sqlite/src/dbevents.cpp
@@ -162,10 +162,12 @@ int CDbxSQLite::DeleteEventMain(MEVENT hDbEvent)
return rc;
}
-int CDbxSQLite::DeleteEventSrt(MEVENT hDbEvent)
+int CDbxSQLite::DeleteEventSrt(MEVENT hDbEvent, MCONTACT hContact, uint32_t ts)
{
- auto *stmt = InitQuery("DELETE FROM events_srt WHERE id = ?;", qEvDelSrt);
+ auto *stmt = InitQuery("DELETE FROM events_srt WHERE id = ? AND contact_id = ? AND timestamp = ?;", qEvDelSrt);
sqlite3_bind_int64(stmt, 1, hDbEvent);
+ sqlite3_bind_int64(stmt, 2, hContact);
+ sqlite3_bind_int64(stmt, 3, ts);
int rc = sqlite3_step(stmt);
logError(rc, __FILE__, __LINE__);
sqlite3_reset(stmt);
@@ -177,7 +179,22 @@ BOOL CDbxSQLite::DeleteEvent(MEVENT hDbEvent)
if (hDbEvent == 0)
return 1;
- MEVENT hContact = GetEventContact(hDbEvent);
+ MEVENT hContact;
+ uint32_t ts;
+ {
+ sqlite3_stmt *stmt = InitQuery("SELECT contact_id, timestamp FROM events WHERE id = ? LIMIT 1;", qEvGetContact2);
+ sqlite3_bind_int64(stmt, 1, hDbEvent);
+ int rc = sqlite3_step(stmt);
+ logError(rc, __FILE__, __LINE__);
+ if (rc != SQLITE_ROW) {
+ sqlite3_reset(stmt);
+ return 2;
+ }
+ hContact = sqlite3_column_int64(stmt, 0);
+ ts = sqlite3_column_int64(stmt, 1);
+ sqlite3_reset(stmt);
+ }
+
DBCachedContact *cc = (hContact) ? m_cache->GetCachedContact(hContact) : &m_system;
if (cc == nullptr)
return 1;
@@ -187,7 +204,7 @@ BOOL CDbxSQLite::DeleteEvent(MEVENT hDbEvent)
if (rc != SQLITE_DONE)
return 1;
- rc = DeleteEventSrt(hDbEvent);
+ rc = DeleteEventSrt(hDbEvent, hContact, ts);
if (rc != SQLITE_DONE)
return 1;
diff --git a/plugins/Dbx_sqlite/src/dbintf.h b/plugins/Dbx_sqlite/src/dbintf.h
index e4c274fb3a..e7a88591c5 100644
--- a/plugins/Dbx_sqlite/src/dbintf.h
+++ b/plugins/Dbx_sqlite/src/dbintf.h
@@ -87,11 +87,11 @@ 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;
+ CQuery qEvCount, qEvAdd, qEvDel, qEvEdit, qEvBlobSize, qEvGet, qEvGetFlags, qEvSetFlags, qEvGetContact, qEvGetContact2;
CQuery qEvFindFirst, qEvFindNext, qEvFindLast, qEvFindPrev, qEvFindUnread, qEvAddSrt, qEvDelSrt, qEvMetaSplit, qEvMetaMerge;
CQuery qEvGetById, qEvUpdateId;
int DeleteEventMain(MEVENT);
- int DeleteEventSrt(MEVENT);
+ int DeleteEventSrt(MEVENT, MCONTACT, uint32_t);
// settings
void InitSettings();
diff --git a/plugins/Dbx_sqlite/src/version.h b/plugins/Dbx_sqlite/src/version.h
index ffe245bc61..dd6c90b600 100644
--- a/plugins/Dbx_sqlite/src/version.h
+++ b/plugins/Dbx_sqlite/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 96
#define __RELEASE_NUM 2
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>