summaryrefslogtreecommitdiff
path: root/plugins/DbChecker
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-02-06 20:39:47 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-02-06 20:39:47 +0300
commit41317031f257ad6a06fa743860aff212074dc416 (patch)
tree4003cfc4c815f8d47d726974f60e2ebf79eb380d /plugins/DbChecker
parentd921b4639288df5e4be1350753ec7f369c2a0023 (diff)
more efficient duplcate events catcher
Diffstat (limited to 'plugins/DbChecker')
-rw-r--r--plugins/DbChecker/src/worker.cpp38
1 files changed, 33 insertions, 5 deletions
diff --git a/plugins/DbChecker/src/worker.cpp b/plugins/DbChecker/src/worker.cpp
index f8d0766b04..5527e3509a 100644
--- a/plugins/DbChecker/src/worker.cpp
+++ b/plugins/DbChecker/src/worker.cpp
@@ -55,6 +55,21 @@ static bool ConvertOldEvent(DBEVENTINFO &dbei)
return true;
}
+static bool CompareContents(const DBEVENTINFO &ev1, const DBEVENTINFO &ev2)
+{
+ if (ev1.cbBlob == 0 && ev2.cbBlob == 0)
+ return true;
+
+ if (ev1.cbBlob == 0 && ev2.cbBlob != 0 || ev1.cbBlob != 0 && ev2.cbBlob == 0)
+ return false;
+
+ // both blobs should be compared
+ if (ev1.pBlob == 0 && ev2.pBlob == 0)
+ return false;
+
+ return !memcmp(ev1.pBlob, ev2.pBlob, ev1.cbBlob);
+}
+
void __cdecl WorkerThread(DbToolOptions *opts)
{
time_t ts = time(nullptr);
@@ -63,14 +78,15 @@ void __cdecl WorkerThread(DbToolOptions *opts)
uint32_t sp = 0;
- if (opts->bMarkRead || opts->bCheckUtf) {
+ if (opts->bMarkRead || opts->bCheckUtf || opts->bCheckDups) {
int nCount = 0, nUtfCount = 0, nDups = 0;
for (auto &cc : Contacts()) {
DB::ECPTR pCursor(DB::Events(cc));
+ DBEVENTINFO dboldev = {};
while (MEVENT hEvent = pCursor.FetchNext()) {
DB::EventInfo dbei;
- if (opts->bCheckUtf) // read also event's body
+ if (opts->bCheckUtf || opts->bCheckDups) // read also event's body
dbei.cbBlob = -1;
if (db_event_get(hEvent, &dbei))
continue;
@@ -87,11 +103,23 @@ void __cdecl WorkerThread(DbToolOptions *opts)
}
}
- if (opts->bCheckDups && DB::IsDuplicateEvent(cc, dbei)) {
- pCursor.DeleteEvent();
- nDups++;
+ if (opts->bCheckDups) {
+ if (dbei == dboldev && CompareContents(dbei, dboldev)) {
+ pCursor.DeleteEvent();
+ nDups++;
+ }
+ else {
+ mir_free(dboldev.pBlob);
+ dboldev = dbei;
+ if (dboldev.cbBlob) {
+ dboldev.pBlob = (uint8_t *)mir_alloc(dboldev.cbBlob);
+ memcpy(dboldev.pBlob, dbei.pBlob, dboldev.cbBlob);
+ }
+ else dboldev.pBlob = nullptr;
+ }
}
}
+ mir_free(dboldev.pBlob);
}
if (nCount)