aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Montel <[email protected]>2018-01-11 14:00:37 +0100
committerLaurent Montel <[email protected]>2018-01-11 14:00:37 +0100
commitd57561ebfd1b552af28807fb43a12ed0a294a855 (patch)
tree9409bdb21c2b3139e86fbf2a9508b226a3e24b50
parent37857b245e0f54d3982e61bafbf87c14601c9621 (diff)
Minor optimization
-rw-r--r--src/server/handler/akappend.cpp14
-rw-r--r--src/server/handler/colcopy.cpp8
-rw-r--r--src/server/handler/colmove.cpp8
-rw-r--r--src/server/handler/copy.cpp14
-rw-r--r--src/server/handler/create.cpp17
-rw-r--r--src/server/handler/delete.cpp8
-rw-r--r--src/server/handler/fetch.cpp6
-rw-r--r--src/server/handler/link.cpp8
-rw-r--r--src/server/handler/list.cpp7
-rw-r--r--src/server/handler/login.cpp2
-rw-r--r--src/server/handler/move.cpp2
-rw-r--r--src/server/handler/status.cpp4
-rw-r--r--src/server/handler/tagappend.cpp2
-rw-r--r--src/server/handler/tagremove.cpp6
14 files changed, 54 insertions, 52 deletions
diff --git a/src/server/handler/akappend.cpp b/src/server/handler/akappend.cpp
index 57398af..7bba2ba 100644
--- a/src/server/handler/akappend.cpp
+++ b/src/server/handler/akappend.cpp
@@ -48,10 +48,10 @@ bool AkAppend::buildPimItem(const Protocol::CreateItemCommand &cmd, PimItem &ite
{
parentCol = HandlerHelper::collectionFromScope(cmd.collection(), connection());
if (!parentCol.isValid()) {
- return failureResponse("Invalid parent collection");
+ return failureResponse(QStringLiteral("Invalid parent collection"));
}
if (parentCol.isVirtual()) {
- return failureResponse("Cannot append item into virtual collection");
+ return failureResponse(QStringLiteral("Cannot append item into virtual collection"));
}
MimeType mimeType = MimeType::retrieveByNameOrCreate(cmd.mimeType());
@@ -87,7 +87,7 @@ bool AkAppend::insertItem(const Protocol::CreateItemCommand &cmd, PimItem &item,
}
if (!item.insert()) {
- return failureResponse("Failed to append item");
+ return failureResponse(QStringLiteral("Failed to append item"));
}
// set message flags
@@ -106,7 +106,7 @@ bool AkAppend::insertItem(const Protocol::CreateItemCommand &cmd, PimItem &item,
const Tag::List tagList = HandlerHelper::tagsFromScope(tags, connection());
bool tagsChanged = false;
if (!DataStore::self()->appendItemsTags(PimItem::List() << item, tagList, &tagsChanged, false, parentCol, true)) {
- return failureResponse("Unable to append item tags.");
+ return failureResponse(QStringLiteral("Unable to append item tags."));
}
}
@@ -382,7 +382,7 @@ bool AkAppend::parseStream()
return false;
}
if (!transaction.commit()) {
- return failureResponse("Failed to commit transaction");
+ return failureResponse(QStringLiteral("Failed to commit transaction"));
}
storageTrx.commit();
} else {
@@ -440,7 +440,7 @@ bool AkAppend::parseStream()
storageTrx.commit();
} else {
qCDebug(AKONADISERVER_LOG) << "Multiple merge candidates:";
- Q_FOREACH (const PimItem &item, result) {
+ for (const PimItem &item : result) {
qCDebug(AKONADISERVER_LOG) << "\tID:" << item.id() << ", RID:" << item.remoteId()
<< ", GID:" << item.gid()
<< ", Collection:" << item.collection().name() << "(" << item.collectionId() << ")"
@@ -448,7 +448,7 @@ bool AkAppend::parseStream()
}
// Nor GID or RID are guaranteed to be unique, so make sure we don't merge
// something we don't want
- return failureResponse("Multiple merge candidates, aborting");
+ return failureResponse(QStringLiteral("Multiple merge candidates, aborting"));
}
}
diff --git a/src/server/handler/colcopy.cpp b/src/server/handler/colcopy.cpp
index 434c763..3643825 100644
--- a/src/server/handler/colcopy.cpp
+++ b/src/server/handler/colcopy.cpp
@@ -91,12 +91,12 @@ bool ColCopy::parseStream()
const Collection source = HandlerHelper::collectionFromScope(cmd.collection(), connection());
if (!source.isValid()) {
- return failureResponse("No valid source specified");
+ return failureResponse(QStringLiteral("No valid source specified"));
}
const Collection target = HandlerHelper::collectionFromScope(cmd.destination(), connection());
if (!target.isValid()) {
- return failureResponse("No valid target specified");
+ return failureResponse(QStringLiteral("No valid target specified"));
}
CacheCleanerInhibitor inhibitor;
@@ -113,11 +113,11 @@ bool ColCopy::parseStream()
Transaction transaction(store, QStringLiteral("COLCOPY"));
if (!copyCollection(source, target)) {
- return failureResponse("Failed to copy collection");
+ return failureResponse(QStringLiteral("Failed to copy collection"));
}
if (!transaction.commit()) {
- return failureResponse("Cannot commit transaction.");
+ return failureResponse(QStringLiteral("Cannot commit transaction."));
}
return successResponse<Protocol::CopyCollectionResponse>();
diff --git a/src/server/handler/colmove.cpp b/src/server/handler/colmove.cpp
index 7a12e88..375c221 100644
--- a/src/server/handler/colmove.cpp
+++ b/src/server/handler/colmove.cpp
@@ -37,7 +37,7 @@ bool ColMove::parseStream()
Collection source = HandlerHelper::collectionFromScope(cmd.collection(), connection());
if (!source.isValid()) {
- return failureResponse("Invalid collection to move");
+ return failureResponse(QStringLiteral("Invalid collection to move"));
}
Collection target;
@@ -46,7 +46,7 @@ bool ColMove::parseStream()
} else {
target = HandlerHelper::collectionFromScope(cmd.destination(), connection());
if (!target.isValid()) {
- return failureResponse("Invalid destination collection");
+ return failureResponse(QStringLiteral("Invalid destination collection"));
}
}
@@ -68,11 +68,11 @@ bool ColMove::parseStream()
Transaction transaction(store, QStringLiteral("COLMOVE"));
if (!store->moveCollection(source, target)) {
- return failureResponse("Unable to reparent collection");
+ return failureResponse(QStringLiteral("Unable to reparent collection"));
}
if (!transaction.commit()) {
- return failureResponse("Cannot commit transaction.");
+ return failureResponse(QStringLiteral("Cannot commit transaction."));
}
return successResponse<Protocol::MoveCollectionResponse>();
diff --git a/src/server/handler/copy.cpp b/src/server/handler/copy.cpp
index 3cb032b..6bb750f 100644
--- a/src/server/handler/copy.cpp
+++ b/src/server/handler/copy.cpp
@@ -67,7 +67,7 @@ void Copy::itemsRetrieved(const QList<qint64> &ids)
SelectQueryBuilder<PimItem> qb;
ItemQueryHelper::itemSetToQuery(ImapSet(ids), qb);
if (!qb.exec()) {
- failureResponse("Unable to retrieve items");
+ failureResponse(QStringLiteral("Unable to retrieve items"));
return;
}
const PimItem::List items = qb.result();
@@ -78,13 +78,13 @@ void Copy::itemsRetrieved(const QList<qint64> &ids)
for (const PimItem &item : items) {
if (!copyItem(item, mTargetCollection)) {
- failureResponse("Unable to copy item");
+ failureResponse(QStringLiteral("Unable to copy item"));
return;
}
}
if (!transaction.commit()) {
- failureResponse("Cannot commit transaction.");
+ failureResponse(QStringLiteral("Cannot commit transaction."));
return;
}
}
@@ -94,19 +94,19 @@ bool Copy::parseStream()
const auto &cmd = Protocol::cmdCast<Protocol::CopyItemsCommand>(m_command);
if (!checkScopeConstraints(cmd.items(), Scope::Uid)) {
- return failureResponse("Only UID copy is allowed");
+ return failureResponse(QStringLiteral("Only UID copy is allowed"));
}
if (cmd.items().isEmpty()) {
- return failureResponse("No items specified");
+ return failureResponse(QStringLiteral("No items specified"));
}
mTargetCollection = HandlerHelper::collectionFromScope(cmd.destination(), connection());
if (!mTargetCollection.isValid()) {
- return failureResponse("No valid target specified");
+ return failureResponse(QStringLiteral("No valid target specified"));
}
if (mTargetCollection.isVirtual()) {
- return failureResponse("Copying items into virtual collections is not allowed");
+ return failureResponse(QStringLiteral("Copying items into virtual collections is not allowed"));
}
CacheCleanerInhibitor inhibitor;
diff --git a/src/server/handler/create.cpp b/src/server/handler/create.cpp
index 286c48f..2c0fe3e 100644
--- a/src/server/handler/create.cpp
+++ b/src/server/handler/create.cpp
@@ -35,7 +35,7 @@ bool Create::parseStream()
const auto &cmd = Protocol::cmdCast<Protocol::CreateCollectionCommand>(m_command);
if (cmd.name().isEmpty()) {
- return failureResponse("Invalid collection name");
+ return failureResponse(QStringLiteral("Invalid collection name"));
}
Collection parent;
@@ -47,16 +47,17 @@ bool Create::parseStream()
if (cmd.parent().scope() != Scope::Invalid && !cmd.parent().isEmpty()) {
parent = HandlerHelper::collectionFromScope(cmd.parent(), connection());
if (!parent.isValid()) {
- return failureResponse("Invalid parent collection");
+ return failureResponse(QStringLiteral("Invalid parent collection"));
}
// check if parent can contain a sub-folder
parentContentTypes = parent.mimeTypes();
bool found = false, foundVirtual = false;
for (const MimeType &mt : qAsConst(parentContentTypes)) {
- if (mt.name() == QLatin1String("inode/directory")) {
+ const QString mtName{mt.name()};
+ if (mtName == QLatin1String("inode/directory")) {
found = true;
- } else if (mt.name() == QLatin1String("application/x-vnd.akonadi.collection.virtual")) {
+ } else if (mtName == QLatin1String("application/x-vnd.akonadi.collection.virtual")) {
foundVirtual = true;
}
if (found && foundVirtual) {
@@ -64,7 +65,7 @@ bool Create::parseStream()
}
}
if (!found && !foundVirtual) {
- return failureResponse("Parent collection can not contain sub-collections");
+ return failureResponse(QStringLiteral("Parent collection can not contain sub-collections"));
}
// If only virtual collections are supported, force every new collection to
@@ -79,7 +80,7 @@ bool Create::parseStream()
const QString sessionId = QString::fromUtf8(connection()->sessionId());
Resource res = Resource::retrieveByName(sessionId);
if (!res.isValid()) {
- return failureResponse("Cannot create top-level collection");
+ return failureResponse(QStringLiteral("Cannot create top-level collection"));
}
resourceId = res.id();
}
@@ -128,12 +129,12 @@ bool Create::parseStream()
const QMap<QByteArray, QByteArray> attrs = cmd.attributes();
for (auto iter = attrs.constBegin(), end = attrs.constEnd(); iter != end; ++iter) {
if (!db->addCollectionAttribute(collection, iter.key(), iter.value())) {
- return failureResponse("Unable to add collection attribute.");
+ return failureResponse(QStringLiteral("Unable to add collection attribute."));
}
}
if (!transaction.commit()) {
- return failureResponse("Unable to commit transaction.");
+ return failureResponse(QStringLiteral("Unable to commit transaction."));
}
db->activeCachePolicy(collection);
diff --git a/src/server/handler/delete.cpp b/src/server/handler/delete.cpp
index cf21c0b..030f590 100644
--- a/src/server/handler/delete.cpp
+++ b/src/server/handler/delete.cpp
@@ -51,25 +51,25 @@ bool Delete::parseStream()
Collection collection = HandlerHelper::collectionFromScope(cmd.collection(), connection());
if (!collection.isValid()) {
- return failureResponse("No such collection.");
+ return failureResponse(QStringLiteral("No such collection."));
}
// handle virtual folders
if (collection.resource().name() == QLatin1String(AKONADI_SEARCH_RESOURCE)) {
// don't delete virtual root
if (collection.parentId() == 0) {
- return failureResponse("Cannot delete virtual root collection");
+ return failureResponse(QStringLiteral("Cannot delete virtual root collection"));
}
}
Transaction transaction(DataStore::self(), QStringLiteral("DELETE"));
if (!deleteRecursive(collection)) {
- return failureResponse("Unable to delete collection");
+ return failureResponse(QStringLiteral("Unable to delete collection"));
}
if (!transaction.commit()) {
- return failureResponse("Unable to commit transaction");
+ return failureResponse(QStringLiteral("Unable to commit transaction"));
}
return successResponse<Protocol::DeleteCollectionResponse>();
diff --git a/src/server/handler/fetch.cpp b/src/server/handler/fetch.cpp
index aa38e62..80d34e7 100644
--- a/src/server/handler/fetch.cpp
+++ b/src/server/handler/fetch.cpp
@@ -32,19 +32,19 @@ bool Fetch::parseStream()
const auto &cmd = Protocol::cmdCast<Protocol::FetchItemsCommand>(m_command);
if (!connection()->context()->setScopeContext(cmd.scopeContext())) {
- return failureResponse("Invalid scope context");
+ return failureResponse(QStringLiteral("Invalid scope context"));
}
// We require context in case we do RID fetch
if (connection()->context()->isEmpty() && cmd.scope().scope() == Scope::Rid) {
- return failureResponse("No FETCH context specified");
+ return failureResponse(QStringLiteral("No FETCH context specified"));
}
CacheCleanerInhibitor inhibitor;
FetchHelper fetchHelper(connection(), cmd.scope(), cmd.fetchScope());
if (!fetchHelper.fetchItems()) {
- return failureResponse("Failed to fetch items");
+ return failureResponse(QStringLiteral("Failed to fetch items"));
}
return successResponse<Protocol::FetchItemsResponse>();
diff --git a/src/server/handler/link.cpp b/src/server/handler/link.cpp
index 0accd92..1c94ed8 100644
--- a/src/server/handler/link.cpp
+++ b/src/server/handler/link.cpp
@@ -38,7 +38,7 @@ bool Link::parseStream()
const Collection collection = HandlerHelper::collectionFromScope(cmd.destination(), connection());
if (!collection.isVirtual()) {
- return failureResponse("Can't link items to non-virtual collections");
+ return failureResponse(QStringLiteral("Can't link items to non-virtual collections"));
}
/* FIXME BIN
@@ -68,7 +68,7 @@ bool Link::parseStream()
*/
if (!qb.exec()) {
- return failureResponse("Unable to execute item query");
+ return failureResponse(QStringLiteral("Unable to execute item query"));
}
const PimItem::List items = qb.result();
@@ -89,7 +89,7 @@ bool Link::parseStream()
toUnlink << item;
}
if (!result) {
- return failureResponse("Failed to modify item reference");
+ return failureResponse(QStringLiteral("Failed to modify item reference"));
}
}
@@ -100,7 +100,7 @@ bool Link::parseStream()
}
if (!transaction.commit()) {
- return failureResponse("Cannot commit transaction.");
+ return failureResponse(QStringLiteral("Cannot commit transaction."));
}
return successResponse<Protocol::LinkItemsResponse>();
diff --git a/src/server/handler/list.cpp b/src/server/handler/list.cpp
index c4f69b2..3907503 100644
--- a/src/server/handler/list.cpp
+++ b/src/server/handler/list.cpp
@@ -363,10 +363,11 @@ void List::retrieveCollections(const Collection &topParent, int depth)
QVariantList mimeTypeIds;
QVariantList attributeIds;
QVariantList ancestorIds;
- mimeTypeIds.reserve(mCollections.size());
- attributeIds.reserve(mCollections.size());
+ const int collectionSize{mCollections.size()};
+ mimeTypeIds.reserve(collectionSize);
+ attributeIds.reserve(collectionSize);
//We'd only require the non-leaf collections, but we don't know which those are, so we take all.
- ancestorIds.reserve(mCollections.size());
+ ancestorIds.reserve(collectionSize);
for (auto it = mCollections.cbegin(), end = mCollections.cend(); it != end; ++it) {
mimeTypeIds << it.key();
attributeIds << it.key();
diff --git a/src/server/handler/login.cpp b/src/server/handler/login.cpp
index ffeba04..01d7028 100644
--- a/src/server/handler/login.cpp
+++ b/src/server/handler/login.cpp
@@ -29,7 +29,7 @@ bool Login::parseStream()
const auto &cmd = Protocol::cmdCast<Protocol::LoginCommand>(m_command);
if (cmd.sessionId().isEmpty()) {
- return failureResponse("Missing session identifier");
+ return failureResponse(QStringLiteral("Missing session identifier"));
}
connection()->setSessionId(cmd.sessionId());
diff --git a/src/server/handler/move.cpp b/src/server/handler/move.cpp
index f83326f..8aae8cb 100644
--- a/src/server/handler/move.cpp
+++ b/src/server/handler/move.cpp
@@ -41,7 +41,6 @@ void Move::itemsRetrieved(const QList<qint64> &ids)
ItemQueryHelper::itemSetToQuery(ImapSet(ids), qb);
qb.addValueCondition(PimItem::collectionIdFullColumnName(), Query::NotEquals, mDestination.id());
- const QDateTime mtime = QDateTime::currentDateTimeUtc();
if (!qb.exec()) {
failureResponse("Unable to execute query");
@@ -53,6 +52,7 @@ void Move::itemsRetrieved(const QList<qint64> &ids)
return;
}
+ const QDateTime mtime = QDateTime::currentDateTimeUtc();
// Split the list by source collection
QMap<Entity::Id /* collection */, PimItem> toMove;
QMap<Entity::Id /* collection */, Collection> sources;
diff --git a/src/server/handler/status.cpp b/src/server/handler/status.cpp
index 2fdfca9..762e98b 100644
--- a/src/server/handler/status.cpp
+++ b/src/server/handler/status.cpp
@@ -36,12 +36,12 @@ bool Status::parseStream()
const Collection col = HandlerHelper::collectionFromScope(cmd.collection(), connection());
if (!col.isValid()) {
- return failureResponse("No status for this folder");
+ return failureResponse(QStringLiteral("No status for this folder"));
}
const CollectionStatistics::Statistics stats = CollectionStatistics::self()->statistics(col);
if (stats.count == -1) {
- return failureResponse("Failed to query statistics.");
+ return failureResponse(QStringLiteral("Failed to query statistics."));
}
auto resp = Protocol::FetchCollectionStatsResponsePtr::create();
diff --git a/src/server/handler/tagappend.cpp b/src/server/handler/tagappend.cpp
index c445dcf..2c0c3ba 100644
--- a/src/server/handler/tagappend.cpp
+++ b/src/server/handler/tagappend.cpp
@@ -37,7 +37,7 @@ bool TagAppend::parseStream()
const auto &cmd = Protocol::cmdCast<Protocol::CreateTagCommand>(m_command);
if (!cmd.remoteId().isEmpty() && !connection()->context()->resource().isValid()) {
- return failureResponse("Only resources can create tags with remote ID");
+ return failureResponse(QStringLiteral("Only resources can create tags with remote ID"));
}
Transaction trx(DataStore::self(), QStringLiteral("TAGAPPEND"));
diff --git a/src/server/handler/tagremove.cpp b/src/server/handler/tagremove.cpp
index cf7e4d9..545a9a8 100644
--- a/src/server/handler/tagremove.cpp
+++ b/src/server/handler/tagremove.cpp
@@ -34,19 +34,19 @@ bool TagRemove::parseStream()
const auto &cmd = Protocol::cmdCast<Protocol::DeleteTagCommand>(m_command);
if (!checkScopeConstraints(cmd.tag(), Scope::Uid)) {
- return failureResponse("Only UID-based TAGREMOVE is supported");
+ return failureResponse(QStringLiteral("Only UID-based TAGREMOVE is supported"));
}
SelectQueryBuilder<Tag> tagQuery;
QueryHelper::setToQuery(cmd.tag().uidSet(), Tag::idFullColumnName(), tagQuery);
if (!tagQuery.exec()) {
- return failureResponse("Failed to obtain tags");
+ return failureResponse(QStringLiteral("Failed to obtain tags"));
}
const Tag::List tags = tagQuery.result();
if (!DataStore::self()->removeTags(tags)) {
- return failureResponse("Failed to remove tags");
+ return failureResponse(QStringLiteral("Failed to remove tags"));
}
return successResponse<Protocol::DeleteTagResponse>();