From 5a3ac5642a0e4bf770d399ae015dd9e65b34cf71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Sun, 5 Feb 2017 22:45:55 +0100 Subject: Msg_Export: Optimize checking ignored contacts/protocols (addresses #609) Makes export about 20% faster. --- plugins/Msg_Export/src/options.cpp | 4 +++ plugins/Msg_Export/src/utils.cpp | 67 +++++++++++++++++--------------------- plugins/Msg_Export/src/utils.h | 1 + 3 files changed, 34 insertions(+), 38 deletions(-) (limited to 'plugins/Msg_Export') diff --git a/plugins/Msg_Export/src/options.cpp b/plugins/Msg_Export/src/options.cpp index cf55041001..d2a027545e 100755 --- a/plugins/Msg_Export/src/options.cpp +++ b/plugins/Msg_Export/src/options.cpp @@ -210,6 +210,10 @@ int nExportCompleatList(HWND hParent, bool bOnlySelected) MCONTACT hContact = (MCONTACT)sItem.lParam; + // Check if we should ignore this contact/protocol + if (!bIsExportEnabled(hContact)) + continue; + list &rclCurList = AllEvents[GetFilePathFromUser(hContact)]; MEVENT hDbEvent = db_event_first(hContact); diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp index 89388048ac..6f0a26d065 100755 --- a/plugins/Msg_Export/src/utils.cpp +++ b/plugins/Msg_Export/src/utils.cpp @@ -1204,50 +1204,44 @@ HANDLE openCreateFile(tstring sFilePath) return hFile; } -int nExportEvent(WPARAM hContact, LPARAM hDbEvent) +bool bIsExportEnabled(MCONTACT hContact) { if (!db_get_b(hContact, MODULE, "EnableLog", 1)) - return 0; + return false; - DBEVENTINFO dbei = {}; - int nSize = db_event_getBlobSize(hDbEvent); - if (nSize > 0) { - dbei.cbBlob = nSize; - dbei.pBlob = (PBYTE)malloc(dbei.cbBlob + 2); - dbei.pBlob[dbei.cbBlob] = 0; - dbei.pBlob[dbei.cbBlob + 1] = 0; - // Double null terminate, this shut pervent most errors - // where the blob received has an invalid format - } + const char *szProto = GetContactProto(hContact); + char szTemp[500]; + mir_snprintf(szTemp, "DisableProt_%s", szProto); + if (!db_get_b(NULL, MODULE, szTemp, 1)) + return false; - if (!db_event_get(hDbEvent, &dbei)) { - // Open/create file for writing - tstring sFilePath = GetFilePathFromUser(hContact); - HANDLE hFile = openCreateFile(sFilePath); - if (hFile == INVALID_HANDLE_VALUE) { - DisplayErrorDialog(LPGENW("Failed to open or create file :\n"), sFilePath, NULL); - } - else { - // Write the event - char szTemp[500]; - mir_snprintf(szTemp, "DisableProt_%s", dbei.szModule); - if (db_get_b(NULL, MODULE, szTemp, 1)) - ExportDBEventInfo(hContact, hFile, sFilePath, dbei); - - // Close the file - CloseHandle(hFile); - } + return true; +} + +int nExportEvent(WPARAM hContact, LPARAM hDbEvent) +{ + if (!bIsExportEnabled(hContact)) + return 0; + + // Open/create file for writing + tstring sFilePath = GetFilePathFromUser(hContact); + HANDLE hFile = openCreateFile(sFilePath); + if (hFile == INVALID_HANDLE_VALUE) { + DisplayErrorDialog(LPGENW("Failed to open or create file :\n"), sFilePath, NULL); + return 0; } - if (dbei.pBlob) - free(dbei.pBlob); + + // Write the event + bExportEvent((MCONTACT)hContact, (MEVENT)hDbEvent, hFile, sFilePath); + + // Close the file + CloseHandle(hFile); + return 0; } bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, tstring sFilePath) { - if (!db_get_b(hContact, MODULE, "EnableLog", 1)) - return 0; - DBEVENTINFO dbei = {}; int nSize = db_event_getBlobSize(hDbEvent); if (nSize > 0) { @@ -1262,10 +1256,7 @@ bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, tstring sFil bool result = true; if (!db_event_get(hDbEvent, &dbei)) { // Write the event - char szTemp[500]; - mir_snprintf(szTemp, "DisableProt_%s", dbei.szModule); - if (db_get_b(NULL, MODULE, szTemp, 1)) - result = ExportDBEventInfo(hContact, hFile, sFilePath, dbei); + result = ExportDBEventInfo(hContact, hFile, sFilePath, dbei); } if (dbei.pBlob) free(dbei.pBlob); diff --git a/plugins/Msg_Export/src/utils.h b/plugins/Msg_Export/src/utils.h index c4f318e133..de0055fccc 100755 --- a/plugins/Msg_Export/src/utils.h +++ b/plugins/Msg_Export/src/utils.h @@ -55,6 +55,7 @@ wchar_t *CheckedTranslate(const wchar_t *szEng, int nFormatCount = -1); void SaveSettings(); void ShowDebugInfo(); +bool bIsExportEnabled(MCONTACT hContact); HANDLE openCreateFile(tstring sFilePath); bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, tstring sFilePath); -- cgit v1.2.3