aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <dvratil@kde.org>2016-08-10 20:52:33 (GMT)
committerDaniel Vrátil <dvratil@kde.org>2016-08-10 20:52:46 (GMT)
commit766c18137eca6195ae2f4742f467c7562b09e255 (patch)
tree46e0c49b7c0fe7efb024f19f14eaf12c0f8dee99
parentae8bfd82ac25ad728e690b954a93efb6e27586a3 (diff)
ItemRetriever: group retrieval requests by Collection
... instead of Resource. Requesting multiple Items from single Collections in one batch makes it easier for Resources to process the request. Since each Collection belongs to exactly one Resource, the Resource groupping is preserved as well.
-rw-r--r--src/server/storage/itemretriever.cpp26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/server/storage/itemretriever.cpp b/src/server/storage/itemretriever.cpp
index f0220ab..44213da 100644
--- a/src/server/storage/itemretriever.cpp
+++ b/src/server/storage/itemretriever.cpp
@@ -125,10 +125,8 @@ QVector<QByteArray> ItemRetriever::retrieveParts() const
enum QueryColumns {
PimItemIdColumn,
- PimItemRidColumn,
-
- MimeTypeIdColumn,
+ CollectionIdColumn,
ResourceIdColumn,
PartTypeNameColumn,
@@ -153,8 +151,7 @@ QSqlQuery ItemRetriever::buildQuery() const
qb.addJoin(QueryBuilder::LeftJoin, PartType::tableName(), partTypeJoinCondition);
qb.addColumn(PimItem::idFullColumnName());
- qb.addColumn(PimItem::remoteIdFullColumnName());
- qb.addColumn(PimItem::mimeTypeIdFullColumnName());
+ qb.addColumn(PimItem::collectionIdFullColumnName());
qb.addColumn(Collection::resourceIdFullColumnName());
qb.addColumn(PartType::nameFullColumnName());
qb.addColumn(Part::datasizeFullColumnName());
@@ -208,27 +205,28 @@ bool ItemRetriever::exec()
QHash<qint64, QString> resourceIdNameCache;
QVector<ItemRetrievalRequest *> requests;
- QHash<QString /* resourceId */, ItemRetrievalRequest*> resRequests;
- QHash<qint64, ItemRetrievalRequest*> itemRequests;
+ QHash<qint64 /* collection */, ItemRetrievalRequest*> colRequests;
+ QHash<qint64 /* item */, ItemRetrievalRequest*> itemRequests;
while (query.isValid()) {
const qint64 pimItemId = query.value(PimItemIdColumn).toLongLong();
+ const qint64 collectionId = query.value(CollectionIdColumn).toLongLong();
const qint64 resourceId = query.value(ResourceIdColumn).toLongLong();
- auto resIter = resourceIdNameCache.find(resourceId);
- if (resIter == resourceIdNameCache.end()) {
- resIter = resourceIdNameCache.insert(resourceId, Resource::retrieveById(resourceId).name());
- }
ItemRetrievalRequest *lastRequest = Q_NULLPTR;
- auto itemIter = itemRequests.constFind(pimItemId);
+ const auto itemIter = itemRequests.constFind(pimItemId);
if (itemIter != itemRequests.constEnd()) {
lastRequest = *itemIter;
} else {
- lastRequest = resRequests.value(*resIter);
+ lastRequest = colRequests.value(collectionId);
if (!lastRequest || lastRequest->ids.size() > 100) {
lastRequest = new ItemRetrievalRequest();
lastRequest->ids.push_back(pimItemId);
+ auto resIter = resourceIdNameCache.find(resourceId);
+ if (resIter == resourceIdNameCache.end()) {
+ resIter = resourceIdNameCache.insert(resourceId, Resource::retrieveById(resourceId).name());
+ }
lastRequest->resourceId = *resIter;
lastRequest->parts = parts;
- resRequests.insert(*resIter, lastRequest);
+ colRequests.insert(collectionId, lastRequest);
itemRequests.insert(pimItemId, lastRequest);
requests << lastRequest;
} else {