Commit 5c3cbeb2 authored by Krzysztof Nowicki's avatar Krzysztof Nowicki Committed by Laurent Montel
Browse files

Optimize item payload retrieval



Make use of the guarantee that the response from the server will
contain the items in the exact order as they were listed in the
request. This allows elimitation of the hash map.
Signed-off-by: Krzysztof Nowicki's avatarKrzysztof Nowicki <krissn@op.pl>
parent bc5af1df
......@@ -53,12 +53,6 @@ void EwsFetchItemPayloadJob::itemFetchFinished(KJob *job)
return;
}
QHash<QString, Item> itemHash;
itemHash.reserve(mItems.count());
for (const Item &item : mItems) {
itemHash.insert(item.remoteId(), item);
}
const EwsGetItemRequest::Response &resp = req->responses()[0];
if (!resp.isSuccess()) {
qCWarningNC(EWSRES_AGENTIF_LOG) << QStringLiteral("retrieveItems: Item fetch failed.");
......@@ -74,11 +68,13 @@ void EwsFetchItemPayloadJob::itemFetchFinished(KJob *job)
return;
}
Q_FOREACH (const EwsGetItemRequest::Response &resp, req->responses()) {
/* In general EWS guarantees that the order of response items will match the order of request items.
* It is therefore safe to iterate these in parallel. */
auto it = mItems.begin();
for (const auto &resp : req->responses()) {
const EwsItem &ewsItem = resp.item();
auto id = ewsItem[EwsItemFieldItemId].value<EwsId>();
auto it = itemHash.find(id.id());
if (it == itemHash.end()) {
if (it->remoteId() != id.id()) {
qCWarningNC(EWSRES_AGENTIF_LOG) << QStringLiteral("retrieveItems: Akonadi item not found for item %1.").arg(id.id());
setErrorText(i18nc("@info:status", "Failed to retrieve items - Akonadi item not found for item %1", id.id()));
emitResult();
......@@ -97,9 +93,8 @@ void EwsFetchItemPayloadJob::itemFetchFinished(KJob *job)
emitResult();
return;
}
++it;
}
mResultItems = itemHash.values().toVector();
emitResult();
}
......@@ -21,7 +21,7 @@ public:
Akonadi::Item::List items() const
{
return mResultItems;
return mItems;
}
void start() override;
Q_SIGNALS:
......@@ -31,6 +31,5 @@ Q_SIGNALS:
private:
void itemFetchFinished(KJob *job);
Akonadi::Item::List mItems;
Akonadi::Item::List mResultItems;
EwsClient &mClient;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment