From 0f8396dd2266cb169797d24bb738d9ff45a003d5 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 7 Dec 2020 12:58:27 +0300 Subject: Dbx_mdbx: we don't have to bother db if we're trying to delete missing setting --- plugins/Dbx_mdbx/src/dbevents.cpp | 2 +- plugins/Dbx_mdbx/src/dbintf.h | 6 +++--- plugins/Dbx_mdbx/src/dbsettings.cpp | 17 ++++++++++------- 3 files changed, 14 insertions(+), 11 deletions(-) (limited to 'plugins/Dbx_mdbx/src') diff --git a/plugins/Dbx_mdbx/src/dbevents.cpp b/plugins/Dbx_mdbx/src/dbevents.cpp index bc16f4f460..203d696b2d 100644 --- a/plugins/Dbx_mdbx/src/dbevents.cpp +++ b/plugins/Dbx_mdbx/src/dbevents.cpp @@ -441,7 +441,7 @@ BOOL CDbxMDBX::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent) /////////////////////////////////////////////////////////////////////////////////////////////////// -MEVENT CDbxMDBX::GetEventById(LPCSTR szModule, LPCSTR szId) +MEVENT CDbxMDBX::GetEventById(const char *szModule, const char *szId) { if (szModule == nullptr || szId == nullptr) return 0; diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h index 80ffeef3d8..cf3bda9553 100644 --- a/plugins/Dbx_mdbx/src/dbintf.h +++ b/plugins/Dbx_mdbx/src/dbintf.h @@ -278,9 +278,9 @@ public: STDMETHODIMP_(BOOL) EnumModuleNames(DBMODULEENUMPROC pFunc, void *pParam) override; - STDMETHODIMP_(BOOL) GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic) override; + STDMETHODIMP_(BOOL) GetContactSettingWorker(MCONTACT contactID, const char *szModule, const char *szSetting, DBVARIANT *dbv, int isStatic) override; STDMETHODIMP_(BOOL) WriteContactSetting(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws) override; - STDMETHODIMP_(BOOL) DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting) override; + STDMETHODIMP_(BOOL) DeleteContactSetting(MCONTACT contactID, const char *szModule, const char *szSetting) override; STDMETHODIMP_(BOOL) EnumContactSettings(MCONTACT hContact, DBSETTINGENUMPROC pfnEnumProc, const char *szModule, void *param) override; STDMETHODIMP_(BOOL) MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) override; @@ -291,7 +291,7 @@ public: STDMETHODIMP_(BOOL) Compact(); STDMETHODIMP_(BOOL) Backup(const wchar_t*); - STDMETHODIMP_(MEVENT) GetEventById(LPCSTR szModule, LPCSTR szId) override; + STDMETHODIMP_(MEVENT) GetEventById(const char *szModule, const char *szId) override; STDMETHODIMP_(DB::EventCursor *) EventCursor(MCONTACT hContact, MEVENT hDbEvent) override; STDMETHODIMP_(DB::EventCursor *) EventCursorRev(MCONTACT hContact, MEVENT hDbEvent) override; diff --git a/plugins/Dbx_mdbx/src/dbsettings.cpp b/plugins/Dbx_mdbx/src/dbsettings.cpp index 523d7a4801..2d85ef0779 100644 --- a/plugins/Dbx_mdbx/src/dbsettings.cpp +++ b/plugins/Dbx_mdbx/src/dbsettings.cpp @@ -99,7 +99,7 @@ void CDbxMDBX::FillSettings() #define VLT(n) ((n == DBVT_UTF8 || n == DBVT_ENCRYPTED)?DBVT_ASCIIZ:n) -static bool ValidLookupName(LPCSTR szModule, LPCSTR szSetting) +static bool ValidLookupName(const char *szModule, const char *szSetting) { if (!strcmp(szModule, META_PROTO)) return strcmp(szSetting, "IsSubcontact") && strcmp(szSetting, "ParentMetaID"); @@ -107,7 +107,7 @@ static bool ValidLookupName(LPCSTR szModule, LPCSTR szSetting) return false; } -int CDbxMDBX::GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic) +int CDbxMDBX::GetContactSettingWorker(MCONTACT contactID, const char *szModule, const char *szSetting, DBVARIANT *dbv, int isStatic) { if (szSetting == nullptr || szModule == nullptr) return 1; @@ -363,7 +363,7 @@ BOOL CDbxMDBX::WriteContactSetting(MCONTACT contactID, DBCONTACTWRITESETTING *db return 0; } -BOOL CDbxMDBX::DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting) +BOOL CDbxMDBX::DeleteContactSetting(MCONTACT contactID, const char *szModule, const char *szSetting) { if (!szModule || !szSetting) return 1; @@ -374,7 +374,13 @@ BOOL CDbxMDBX::DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR mir_cslock lck(m_csDbAccess); char *szCachedSettingName = m_cache->GetCachedSetting(szModule, szSetting, moduleNameLen, settingNameLen); - // it's not a resident variable, delete it from database too + // try to remove it from cache first. + // if there's nothing, don't try to remove a setting from database + auto *pSetting = m_cache->GetCachedValuePtr(contactID, szCachedSettingName, -1); + if (pSetting == nullptr) + return 1; + + // if it's not a resident variable, delete it from database too if (szCachedSettingName[-1] == 0) { DBSettingKey *keyVal = (DBSettingKey*)_alloca(sizeof(DBSettingKey) + settingNameLen); keyVal->hContact = contactID; @@ -387,9 +393,6 @@ BOOL CDbxMDBX::DeleteContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR return 1; DBFlush(); } - - // and don't forget to remove it from cache - m_cache->GetCachedValuePtr(contactID, szCachedSettingName, -1); } // notify -- cgit v1.2.3