Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit d57561eb authored by Laurent Montel's avatar Laurent Montel 😁

Minor optimization

parent 37857b24
......@@ -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"));
}
}
......
......@@ -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>();
......
......@@ -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>();
......
......@@ -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;
......
......@@ -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);
......
......@@ -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>();
......
......@@ -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>();
......
......@@ -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>();
......
......@@ -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();
......
......@@ -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());
......
......@@ -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;
......
......@@ -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();
......
......@@ -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"));
......
......@@ -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>();
......
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