diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2016-04-25 16:04:06 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2016-04-25 16:04:06 +0000 |
commit | 3bf8dd214686baa698ec98c16d49f320d6f4eee8 (patch) | |
tree | d3786a64c6929919225ed2086deb8e59008f6a8f /protocols/SkypeWeb/src | |
parent | ab53e157ddc1eddbfa072d43d62d244443f41815 (diff) |
SkypeWeb: database optimization
git-svn-id: http://svn.miranda-ng.org/main/trunk@16765 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/SkypeWeb/src')
-rw-r--r-- | protocols/SkypeWeb/src/skype_avatars.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_chatrooms.cpp | 3 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_contacts.cpp | 14 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_db.h | 9 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_dialogs.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_files.cpp | 4 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_history_sync.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_messages.cpp | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.cpp | 13 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.h | 33 |
10 files changed, 52 insertions, 32 deletions
diff --git a/protocols/SkypeWeb/src/skype_avatars.cpp b/protocols/SkypeWeb/src/skype_avatars.cpp index 33e9837bb6..626773ab1d 100644 --- a/protocols/SkypeWeb/src/skype_avatars.cpp +++ b/protocols/SkypeWeb/src/skype_avatars.cpp @@ -136,7 +136,7 @@ void CSkypeProto::GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t cb pszDest[tPathLen++] = '\\';
const TCHAR* szFileType = ProtoGetAvatarExtension(getByte(hContact, "AvatarType", PA_FORMAT_JPEG));
- CMStringA username(ptrA(getStringA(hContact, SKYPE_SETTINGS_ID)));
+ CMStringA username(Contacts[hContact]);
username.Replace("live:", "__live_");
username.Replace("facebook:", "__facebook_");
mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%S%s"), username.c_str(), szFileType);
diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp index 7c052adb32..e227e3b85b 100644 --- a/protocols/SkypeWeb/src/skype_chatrooms.cpp +++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp @@ -182,8 +182,7 @@ int CSkypeProto::OnGroupChatEventHook(WPARAM, LPARAM lParam) MCONTACT hContact = dlg.m_hContact;
if (hContact != NULL)
{
- ptrA username(db_get_sa(hContact, m_szModuleName, SKYPE_SETTINGS_ID));
- SendRequest(new InviteUserToChatRequest(chat_id, username, "User", li));
+ SendRequest(new InviteUserToChatRequest(chat_id, Contacts[hContact], "User", li));
}
{ mir_cslock lck(m_InviteDialogsLock); m_InviteDialogs.remove(&dlg); }
diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp index d88603cb6c..174cc0e7fd 100644 --- a/protocols/SkypeWeb/src/skype_contacts.cpp +++ b/protocols/SkypeWeb/src/skype_contacts.cpp @@ -77,7 +77,7 @@ MCONTACT CSkypeProto::FindContact(const char *skypename) MCONTACT hContact = NULL;
for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
{
- if (!mir_strcmpi(skypename, CID(this, hContact)))
+ if (!mir_strcmpi(skypename, Contacts[hContact]))
break;
}
return hContact;
@@ -299,8 +299,7 @@ INT_PTR CSkypeProto::OnRequestAuth(WPARAM hContact, LPARAM) if (hContact == INVALID_CONTACT_ID)
return 1;
- ptrA skypename(getStringA(hContact, SKYPE_SETTINGS_ID));
- PushRequest(new AddContactRequest(li, skypename));
+ PushRequest(new AddContactRequest(li, Contacts[hContact]));
return 0;
}
@@ -309,8 +308,7 @@ INT_PTR CSkypeProto::OnGrantAuth(WPARAM hContact, LPARAM) if (hContact == INVALID_CONTACT_ID)
return 1;
- ptrA skypename(getStringA(hContact, SKYPE_SETTINGS_ID));
- PushRequest(new AuthAcceptRequest(li, skypename));
+ PushRequest(new AuthAcceptRequest(li, Contacts[hContact]));
return 0;
}
@@ -319,7 +317,7 @@ int CSkypeProto::OnContactDeleted(MCONTACT hContact, LPARAM) if (!IsOnline()) return 1;
if (hContact && !isChatRoom(hContact))
- PushRequest(new DeleteContactRequest(li, ptrA(db_get_sa(hContact, m_szModuleName, SKYPE_SETTINGS_ID))));
+ PushRequest(new DeleteContactRequest(li, Contacts[hContact]));
return 0;
}
@@ -328,7 +326,7 @@ INT_PTR CSkypeProto::BlockContact(WPARAM hContact, LPARAM) if (!IsOnline()) return 1;
if (IDYES == MessageBox(NULL, TranslateT("Are you sure?"), TranslateT("Warning"), MB_YESNO | MB_ICONQUESTION))
- SendRequest(new BlockContactRequest(li, ptrA(db_get_sa(hContact, m_szModuleName, SKYPE_SETTINGS_ID))), &CSkypeProto::OnBlockContact, (void *)hContact);
+ SendRequest(new BlockContactRequest(li, Contacts[hContact]), &CSkypeProto::OnBlockContact, (void *)hContact);
return 0;
}
@@ -343,7 +341,7 @@ void CSkypeProto::OnBlockContact(const NETLIBHTTPREQUEST *response, void *p) INT_PTR CSkypeProto::UnblockContact(WPARAM hContact, LPARAM)
{
- SendRequest(new UnblockContactRequest(li, ptrA(db_get_sa(hContact, m_szModuleName, SKYPE_SETTINGS_ID))), &CSkypeProto::OnUnblockContact, (void *)hContact);
+ SendRequest(new UnblockContactRequest(li, Contacts[hContact]), &CSkypeProto::OnUnblockContact, (void *)hContact);
return 0;
}
diff --git a/protocols/SkypeWeb/src/skype_db.h b/protocols/SkypeWeb/src/skype_db.h index cd101386a3..ac2d0906fc 100644 --- a/protocols/SkypeWeb/src/skype_db.h +++ b/protocols/SkypeWeb/src/skype_db.h @@ -63,13 +63,4 @@ struct CSkypeOptions };
-class CID
-{
- ptrA m_value;
-public:
- inline CID(PROTO_INTERFACE *ppro, const MCONTACT hContact) : m_value(ppro->getStringA(hContact, SKYPE_SETTINGS_ID)) {}
- inline operator char *() { return m_value; }
-};
-
-
#endif //_SKYPE_DB_H_
\ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_dialogs.cpp b/protocols/SkypeWeb/src/skype_dialogs.cpp index 6f38f8d433..4624bb5c45 100644 --- a/protocols/SkypeWeb/src/skype_dialogs.cpp +++ b/protocols/SkypeWeb/src/skype_dialogs.cpp @@ -88,7 +88,7 @@ void CSkypeGCCreateDlg::btnOk_OnOk(CCtrlButton*) {
if (m_clc.GetCheck(hItem))
{
- char *szName = db_get_sa(hContact, m_proto->m_szModuleName, SKYPE_SETTINGS_ID);
+ char *szName = mir_strdup(m_proto->Contacts[hContact]);
if (szName != NULL)
m_ContactsList.insert(szName);
}
diff --git a/protocols/SkypeWeb/src/skype_files.cpp b/protocols/SkypeWeb/src/skype_files.cpp index d6c1d38f02..8773ed4d4b 100644 --- a/protocols/SkypeWeb/src/skype_files.cpp +++ b/protocols/SkypeWeb/src/skype_files.cpp @@ -27,7 +27,7 @@ void CSkypeProto::SendFileThread(void *p) ProtoBroadcastAck(fup->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTING, (HANDLE)fup);
T2Utf uszFileName(fup->tszFileName);
- SendRequest(new ASMObjectCreateRequest(li, CMStringA(FORMAT, "%d:%s", isChatRoom(fup->hContact) ? 19 : 8, ptrA(getStringA(fup->hContact, SKYPE_SETTINGS_ID))), strrchr((const char*)uszFileName + 1, '\\')), &CSkypeProto::OnASMObjectCreated, fup);
+ SendRequest(new ASMObjectCreateRequest(li, CMStringA(FORMAT, "%d:%s", isChatRoom(fup->hContact) ? 19 : 8, Contacts[fup->hContact]), strrchr((const char*)uszFileName + 1, '\\')), &CSkypeProto::OnASMObjectCreated, fup);
}
void CSkypeProto::OnASMObjectCreated(const NETLIBHTTPREQUEST *response, void *arg)
@@ -92,7 +92,7 @@ void CSkypeProto::OnASMObjectUploaded(const NETLIBHTTPREQUEST *response, void *a xmlAddAttr(xml, L"uri", CMStringW(FORMAT, L"https://api.asm.skype.com/v1/objects/%s", _A2T(fup->uid)));
xmlAddAttr(xml, L"url_thumbnail", CMStringW(FORMAT, L"https://api.asm.skype.com/v1/objects/%s/views/thumbnail", _A2T(fup->uid)));
- SendRequest(new SendMessageRequest(ptrA(getStringA(fup->hContact, SKYPE_SETTINGS_ID)), time(NULL), T2Utf(ptrT(xmlToString(xml, nullptr))), li, "RichText/Media_GenericFile"));
+ SendRequest(new SendMessageRequest(Contacts[fup->hContact], time(NULL), T2Utf(ptrT(xmlToString(xml, nullptr))), li, "RichText/Media_GenericFile"));
xmlDestroyNode(xml);
ProtoBroadcastAck(fup->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, (HANDLE)fup);
delete fup;
diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index db2a34ec14..d8715e94fa 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -115,7 +115,7 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) INT_PTR CSkypeProto::GetContactHistory(WPARAM hContact, LPARAM)
{
- PushRequest(new GetHistoryRequest(ptrA(db_get_sa(hContact, m_szModuleName, SKYPE_SETTINGS_ID)), 100, false, 0, li), &CSkypeProto::OnGetServerHistory);
+ PushRequest(new GetHistoryRequest(Contacts[hContact], 100, false, 0, li), &CSkypeProto::OnGetServerHistory);
return 0;
}
diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index 2fd99c5d67..b9c2257093 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -270,7 +270,7 @@ void CSkypeProto::MarkMessagesRead(MCONTACT hContact, MEVENT hDbEvent) time_t timestamp = dbei.timestamp;
if(db_get_dw(hContact, m_szModuleName, "LastMsgTime", 0) > (timestamp - 300))
- PushRequest(new MarkMessageReadRequest(CID(this, hContact), timestamp, timestamp, false, li));
+ PushRequest(new MarkMessageReadRequest(Contacts[hContact], timestamp, timestamp, false, li));
}
diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index 2032ab0c6b..fbe2cfd705 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -26,7 +26,8 @@ CSkypeProto::CSkypeProto(const char* protoName, const TCHAR* userName) : m_bThreadsTerminated(0),
m_TrouterConnection(0),
m_pollingConnection(0),
- m_opts(this)
+ m_opts(this),
+ Contacts(this)
{
InitNetwork();
@@ -156,7 +157,7 @@ int CSkypeProto::Authorize(MEVENT hDbEvent) if (hContact == INVALID_CONTACT_ID)
return 1;
- PushRequest(new AuthAcceptRequest(li, CID(this, hContact)));
+ PushRequest(new AuthAcceptRequest(li, Contacts[hContact]));
return 0;
}
@@ -166,7 +167,7 @@ int CSkypeProto::AuthDeny(MEVENT hDbEvent, const TCHAR*) if (hContact == INVALID_CONTACT_ID)
return 1;
- PushRequest(new AuthDeclineRequest(li, CID(this, hContact)));
+ PushRequest(new AuthDeclineRequest(li, Contacts[hContact]));
return 0;
}
@@ -180,7 +181,7 @@ int CSkypeProto::AuthRequest(MCONTACT hContact, const TCHAR *szMessage) if (hContact == INVALID_CONTACT_ID)
return 1;
- PushRequest(new AddContactRequest(li, CID(this, hContact), T2Utf(szMessage)));
+ PushRequest(new AddContactRequest(li, Contacts[hContact], T2Utf(szMessage)));
return 0;
}
@@ -188,7 +189,7 @@ int CSkypeProto::GetInfo(MCONTACT hContact, int) {
if (!isChatRoom(hContact))
PushRequest(
- new GetProfileRequest(li, CID(this, hContact)),
+ new GetProfileRequest(li, Contacts[hContact]),
&CSkypeProto::LoadProfile);
return 0;
}
@@ -265,7 +266,7 @@ int CSkypeProto::SetStatus(int iNewStatus) int CSkypeProto::UserIsTyping(MCONTACT hContact, int type)
{
- SendRequest(new SendTypingRequest(CID(this, hContact), type, li));
+ SendRequest(new SendTypingRequest(Contacts[hContact], type, li));
return 0;
}
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index b5ce6cf33a..63693910f9 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -89,7 +89,38 @@ private: LoginInfo li;
-
+ struct contacts_list
+ {
+ CSkypeProto *m_proto;
+ std::map<MCONTACT, char*> m_cache;
+
+ contacts_list(CSkypeProto *ppro) : m_proto(ppro)
+ {}
+
+ ~contacts_list()
+ {
+ for (auto it = m_cache.begin(); it != m_cache.end(); ++it)
+ {
+ mir_free(it->second);
+ }
+ }
+
+ const char* operator[](MCONTACT hContact)
+ {
+ try
+ {
+ return m_cache.at(hContact);
+ }
+ catch (std::out_of_range&)
+ {
+ char *id = m_proto->getStringA(hContact, SKYPE_SETTINGS_ID);
+ m_cache[hContact] = id;
+ return id;
+ }
+ }
+
+ } Contacts;
+
static UINT_PTR m_timer;
|