Merge lp:~phablet-team/history-service/improve_roles_management into lp:history-service/staging

Proposed by Tiago Salem Herrmann
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 258
Merged at revision: 258
Proposed branch: lp:~phablet-team/history-service/improve_roles_management
Merge into: lp:history-service/staging
Prerequisite: lp:~phablet-team/history-service/wait_for_self_not_pending
Diff against target: 196 lines (+65/-18)
5 files modified
Ubuntu/History/historyeventmodel.cpp (+17/-6)
daemon/historydaemon.cpp (+43/-11)
daemon/historydaemon.h (+3/-1)
daemon/textchannelobserver.cpp (+1/-0)
daemon/textchannelobserver.h (+1/-0)
To merge this branch: bzr merge lp:~phablet-team/history-service/improve_roles_management
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
Review via email: mp+316377@code.launchpad.net

Commit message

Improve Roles management performance by caching the retrieved data.

Description of the change

Improve Roles management performance by caching the retrieved data.

To post a comment you must log in.
257. By Tiago Salem Herrmann

merge parent branch

258. By Tiago Salem Herrmann

merge parent branch

Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Ubuntu/History/historyeventmodel.cpp'
2--- Ubuntu/History/historyeventmodel.cpp 2017-02-21 15:16:23 +0000
3+++ Ubuntu/History/historyeventmodel.cpp 2017-02-21 15:16:23 +0000
4@@ -98,7 +98,14 @@
5 result = History::ContactMatcher::normalizeId(event.senderId());
6 break;
7 case SenderRole:
8- result = History::ContactMatcher::instance()->contactInfo(event.accountId(), event.senderId());
9+ if (mMatchContacts) {
10+ result = History::ContactMatcher::instance()->contactInfo(event.accountId(), event.senderId());
11+ } else {
12+ QVariantMap map;
13+ map[History::FieldIdentifier] = event.senderId();
14+ map[History::FieldAccountId] = event.accountId();
15+ result = map;
16+ }
17 break;
18 case TimestampRole:
19 result = event.timestamp();
20@@ -173,12 +180,16 @@
21 break;
22 case SubjectAsAliasRole:
23 if (!textEvent.isNull()) {
24- QVariantMap contactInfo = History::ContactMatcher::instance()->contactInfo(event.accountId(), textEvent.subject());
25- QString returnValue = contactInfo[History::FieldAlias].toString();
26- if (returnValue.isEmpty()) {
27- returnValue = contactInfo[History::FieldIdentifier].toString();
28+ if (mMatchContacts) {
29+ QVariantMap contactInfo = History::ContactMatcher::instance()->contactInfo(event.accountId(), textEvent.subject());
30+ QString returnValue = contactInfo[History::FieldAlias].toString();
31+ if (returnValue.isEmpty()) {
32+ returnValue = contactInfo[History::FieldIdentifier].toString();
33+ }
34+ return returnValue;
35+
36 }
37- return returnValue;
38+ return textEvent.subject();
39 }
40 break;
41 }
42
43=== modified file 'daemon/historydaemon.cpp'
44--- daemon/historydaemon.cpp 2017-02-21 15:16:23 +0000
45+++ daemon/historydaemon.cpp 2017-02-21 15:16:23 +0000
46@@ -145,6 +145,9 @@
47 connect(&mTextObserver,
48 SIGNAL(channelAvailable(Tp::TextChannelPtr)),
49 SLOT(onTextChannelAvailable(Tp::TextChannelPtr)));
50+ connect(&mTextObserver,
51+ SIGNAL(textChannelInvalidated(Tp::TextChannelPtr)),
52+ SLOT(onTextChannelInvalidated(Tp::TextChannelPtr)));
53
54 // FIXME: we need to do this in a better way, but for now this should do
55 mProtocolFlags["ofono"] = History::MatchPhoneNumber;
56@@ -163,23 +166,39 @@
57
58 void HistoryDaemon::onRolesChanged(const HandleRolesMap &added, const HandleRolesMap &removed)
59 {
60- Q_UNUSED(added);
61- Q_UNUSED(removed);
62-
63 ChannelInterfaceRolesInterface *roles_interface = qobject_cast<ChannelInterfaceRolesInterface*>(sender());
64- RolesMap roles = roles_interface->getRoles();
65-
66 Tp::TextChannelPtr channel(qobject_cast<Tp::TextChannel*>(sender()->parent()));
67+ RolesMap rolesMap;
68+ if (!mRolesMap.contains(channel->objectPath())) {
69+ rolesMap = roles_interface->getRoles();
70+ } else {
71+ rolesMap = mRolesMap[channel->objectPath()];
72+ }
73+
74+ QMapIterator<uint, uint> it(removed);
75+ while (it.hasNext()) {
76+ it.next();
77+ rolesMap.remove(it.key());
78+ }
79+
80+ QMapIterator<uint, uint> it2(added);
81+ while (it2.hasNext()) {
82+ it2.next();
83+ rolesMap[it2.key()] = it2.value();
84+ }
85+
86+ mRolesMap[channel->objectPath()] = rolesMap;
87+
88 QVariantMap properties = propertiesFromChannel(channel);
89 QVariantMap thread = threadForProperties(channel->property(History::FieldAccountId).toString(),
90 History::EventTypeText,
91 properties,
92 matchFlagsForChannel(channel),
93 false);
94-
95- writeRolesInformationEvents(thread, channel, roles);
96-
97- updateRoomRoles(channel, roles);
98+ if (!thread.isEmpty()) {
99+ writeRolesInformationEvents(thread, channel, rolesMap);
100+ updateRoomRoles(channel, rolesMap);
101+ }
102 }
103
104 QVariantMap HistoryDaemon::propertiesFromChannel(const Tp::ChannelPtr &textChannel)
105@@ -192,7 +211,9 @@
106 ChannelInterfaceRolesInterface *roles_interface = textChannel->optionalInterface<ChannelInterfaceRolesInterface>();
107 RolesMap roles;
108 if (roles_interface) {
109- roles = roles_interface->getRoles();
110+ if (mRolesMap.contains(textChannel->objectPath())) {
111+ roles = mRolesMap[textChannel->objectPath()];
112+ }
113 }
114
115 Q_FOREACH(const Tp::ContactPtr contact, textChannel->groupContacts(false)) {
116@@ -642,6 +663,11 @@
117 writeEvents(QList<QVariantMap>() << event, properties);
118 }
119
120+void HistoryDaemon::onTextChannelInvalidated(const Tp::TextChannelPtr channel)
121+{
122+ mRolesMap.remove(channel->objectPath());
123+}
124+
125 void HistoryDaemon::onTextChannelAvailable(const Tp::TextChannelPtr channel)
126 {
127 // for Rooms we need to explicitly create the thread to allow users to send messages to groups even
128@@ -828,8 +854,14 @@
129
130 ChannelInterfaceRolesInterface *roles_interface = channel->optionalInterface<ChannelInterfaceRolesInterface>();
131 RolesMap roles;
132+
133 if (roles_interface) {
134- roles = roles_interface->getRoles();
135+ if (!mRolesMap.contains(channel->objectPath())) {
136+ roles = roles_interface->getRoles();
137+ mRolesMap[channel->objectPath()] = roles;
138+ } else {
139+ roles = mRolesMap[channel->objectPath()];
140+ }
141 }
142
143 Q_FOREACH(const Tp::ContactPtr contact, channel->groupRemotePendingContacts(false)) {
144
145=== modified file 'daemon/historydaemon.h'
146--- daemon/historydaemon.h 2017-02-21 15:16:23 +0000
147+++ daemon/historydaemon.h 2017-02-21 15:16:23 +0000
148@@ -42,7 +42,7 @@
149
150 static HistoryDaemon *instance();
151
152- static QVariantMap propertiesFromChannel(const Tp::ChannelPtr &textChannel);
153+ QVariantMap propertiesFromChannel(const Tp::ChannelPtr &textChannel);
154 QVariantMap threadForProperties(const QString &accountId,
155 History::EventType type,
156 const QVariantMap &properties,
157@@ -70,6 +70,7 @@
158 void onMessageRead(const Tp::TextChannelPtr textChannel, const Tp::ReceivedMessage &message);
159 void onMessageSent(const Tp::TextChannelPtr textChannel, const Tp::Message &message, const QString &messageToken);
160 void onTextChannelAvailable(const Tp::TextChannelPtr channel);
161+ void onTextChannelInvalidated(const Tp::TextChannelPtr channel);
162 void onRoomPropertiesChanged(const QVariantMap &properties,const QStringList &invalidated);
163 void onGroupMembersChanged(const Tp::Contacts &groupMembersAdded, const Tp::Contacts &groupLocalPendingMembersAdded,
164 const Tp::Contacts &groupRemotePendingMembersAdded, const Tp::Contacts &groupMembersRemoved,
165@@ -98,6 +99,7 @@
166 QMap<QString, History::MatchFlags> mProtocolFlags;
167 History::PluginPtr mBackend;
168 HistoryServiceDBus mDBus;
169+ QMap<QString, RolesMap> mRolesMap;
170 };
171
172 #endif
173
174=== modified file 'daemon/textchannelobserver.cpp'
175--- daemon/textchannelobserver.cpp 2016-08-26 14:10:25 +0000
176+++ daemon/textchannelobserver.cpp 2017-02-21 15:16:23 +0000
177@@ -57,6 +57,7 @@
178 {
179 Tp::TextChannelPtr textChannel(qobject_cast<Tp::TextChannel*>(sender()));
180 mChannels.removeAll(textChannel);
181+ Q_EMIT textChannelInvalidated(textChannel);
182 }
183
184 void TextChannelObserver::onMessageReceived(const Tp::ReceivedMessage &message)
185
186=== modified file 'daemon/textchannelobserver.h'
187--- daemon/textchannelobserver.h 2016-08-26 14:10:25 +0000
188+++ daemon/textchannelobserver.h 2017-02-21 15:16:23 +0000
189@@ -37,6 +37,7 @@
190
191 Q_SIGNALS:
192 void channelAvailable(const Tp::TextChannelPtr textChannel);
193+ void textChannelInvalidated(const Tp::TextChannelPtr textChannel);
194 void messageReceived(const Tp::TextChannelPtr textChannel, const Tp::ReceivedMessage &message);
195 void messageRead(const Tp::TextChannelPtr textChannel, const Tp::ReceivedMessage &message);
196 void messageSent(const Tp::TextChannelPtr textChannel, const Tp::Message &message, const QString &messageToken);

Subscribers

People subscribed via source and target branches

to all changes: