Commit 32884f46 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Pass CommandContext around as a reference instead of a pointer

parent 2b537887
......@@ -26,6 +26,7 @@
#include "storage/itemretrievaljob.h"
#include "storage/itemretrievalmanager.h"
#include "storage/itemretrievalrequest.h"
#include "commandcontext.h"
#include "fakeakonadiserver.h"
#include "dbinitializer.h"
......@@ -157,7 +158,8 @@ public:
void run() override
{
// ItemRetriever should...
ItemRetriever retriever;
CommandContext context;
ItemRetriever retriever(nullptr, context);
retriever.setItem(m_itemId);
retriever.setRetrieveParts(m_requestedParts);
QSignalSpy spy(&retriever, &ItemRetriever::itemsRetrieved);
......@@ -216,7 +218,8 @@ public:
private Q_SLOTS:
void testFullPayload()
{
ItemRetriever r1(nullptr);
CommandContext context;
ItemRetriever r1(nullptr, context);
r1.setRetrieveFullPayload(true);
QCOMPARE(r1.retrieveParts().size(), 1);
QCOMPARE(r1.retrieveParts().at(0), { "PLD:RFC822" });
......
......@@ -78,9 +78,9 @@ Collection CommandContext::collection() const
return mCollection;
}
void CommandContext::setTag(qint64 tagId)
void CommandContext::setTag(akOptional<qint64> tagId)
{
mTagId = tagId;
mTagId = std::move(tagId);
}
akOptional<qint64> CommandContext::tagId() const
......
......@@ -38,8 +38,6 @@ namespace Server
class CommandContext
{
public:
CommandContext() = default;
void setResource(const Resource &resource);
Resource resource() const;
......@@ -49,7 +47,7 @@ public:
qint64 collectionId() const;
Collection collection() const;
void setTag(qint64 tagId);
void setTag(akOptional<qint64> tagId);
akOptional<qint64> tagId() const;
Tag tag() const;
......
......@@ -256,8 +256,8 @@ void Connection::handleIncomingData()
}
// Tag context and collection context is not persistent.
context()->setTag(-1);
context()->setCollection(Collection());
m_context.setTag(nullopt);
m_context.setCollection({});
if (Tracer::self()->currentTracer() != QLatin1String("null")) {
Tracer::self()->connectionInput(m_identifier, tag, cmd);
}
......@@ -356,9 +356,14 @@ void Connection::handleIncomingData()
}
}
CommandContext *Connection::context() const
const CommandContext &Connection::context() const
{
return const_cast<CommandContext *>(&m_context);
return m_context;
}
void Connection::setContext(const CommandContext &context)
{
m_context = context;
}
std::unique_ptr<Handler> Connection::findHandlerForCommand(Protocol::Command::Type command)
......@@ -429,7 +434,7 @@ QByteArray Connection::sessionId() const
bool Connection::isOwnerResource(const PimItem &item) const
{
if (context()->resource().isValid() && item.collection().resourceId() == context()->resource().id()) {
if (context().resource().isValid() && item.collection().resourceId() == context().resource().id()) {
return true;
}
// fallback for older resources
......@@ -441,7 +446,7 @@ bool Connection::isOwnerResource(const PimItem &item) const
bool Connection::isOwnerResource(const Collection &collection) const
{
if (context()->resource().isValid() && collection.resourceId() == context()->resource().id()) {
if (context().resource().isValid() && collection.resourceId() == context().resource().id()) {
return true;
}
if (sessionId() == collection.resource().name().toUtf8()) {
......
......@@ -58,7 +58,8 @@ public:
virtual DataStore *storageBackend();
CommandContext *context() const;
const CommandContext &context() const;
void setContext(const CommandContext &context);
/**
Returns @c true if this connection belongs to the owning resource of @p item.
......
......@@ -80,12 +80,12 @@ bool CollectionCopyHandler::parseStream()
{
const auto &cmd = Protocol::cmdCast<Protocol::CopyCollectionCommand>(m_command);
const Collection source = HandlerHelper::collectionFromScope(cmd.collection(), connection());
const Collection source = HandlerHelper::collectionFromScope(cmd.collection(), connection()->context());
if (!source.isValid()) {
return failureResponse(QStringLiteral("No valid source specified"));
}
const Collection target = HandlerHelper::collectionFromScope(cmd.destination(), connection());
const Collection target = HandlerHelper::collectionFromScope(cmd.destination(), connection()->context());
if (!target.isValid()) {
return failureResponse(QStringLiteral("No valid target specified"));
}
......@@ -93,7 +93,7 @@ bool CollectionCopyHandler::parseStream()
CacheCleanerInhibitor inhibitor;
// retrieve all not yet cached items of the source
ItemRetriever retriever(connection());
ItemRetriever retriever(connection(), connection()->context());
retriever.setCollection(source, true);
retriever.setRetrieveFullPayload(true);
if (!retriever.exec()) {
......
......@@ -46,7 +46,7 @@ bool CollectionCreateHandler::parseStream()
// Invalid or empty scope means we refer to root collection
if (cmd.parent().scope() != Scope::Invalid && !cmd.parent().isEmpty()) {
parent = HandlerHelper::collectionFromScope(cmd.parent(), connection());
parent = HandlerHelper::collectionFromScope(cmd.parent(), connection()->context());
if (!parent.isValid()) {
return failureResponse(QStringLiteral("Invalid parent collection"));
}
......
......@@ -49,7 +49,7 @@ bool CollectionDeleteHandler::parseStream()
{
const auto &cmd = Protocol::cmdCast<Protocol::DeleteCollectionCommand>(m_command);
Collection collection = HandlerHelper::collectionFromScope(cmd.collection(), connection());
Collection collection = HandlerHelper::collectionFromScope(cmd.collection(), connection()->context());
if (!collection.isValid()) {
return failureResponse(QStringLiteral("No such collection."));
}
......
......@@ -537,8 +537,8 @@ bool CollectionFetchHandler::parseStream()
}
if (mResource.isValid()) {
qb.addValueCondition(Resource::idFullColumnName(), Query::Equals, mResource.id());
} else if (connection()->context()->resource().isValid()) {
qb.addValueCondition(Resource::idFullColumnName(), Query::Equals, connection()->context()->resource().id());
} else if (connection()->context().resource().isValid()) {
qb.addValueCondition(Resource::idFullColumnName(), Query::Equals, connection()->context().resource().id());
} else {
return failureResponse("Cannot retrieve collection based on remote identifier without a resource context");
}
......@@ -551,10 +551,10 @@ bool CollectionFetchHandler::parseStream()
}
col = results.first();
} else if (scope.scope() == Scope::HierarchicalRid) {
if (!connection()->context()->resource().isValid()) {
if (!connection()->context().resource().isValid()) {
return failureResponse("Cannot retrieve collection based on hierarchical remote identifier without a resource context");
}
col = CollectionQueryHelper::resolveHierarchicalRID(scope.hridChain(), connection()->context()->resource().id());
col = CollectionQueryHelper::resolveHierarchicalRID(scope.hridChain(), connection()->context().resource().id());
} else {
return failureResponse("Unexpected error");
}
......
......@@ -41,7 +41,7 @@ bool CollectionModifyHandler::parseStream()
{
const auto &cmd = Protocol::cmdCast<Protocol::ModifyCollectionCommand>(m_command);
Collection collection = HandlerHelper::collectionFromScope(cmd.collection(), connection());
Collection collection = HandlerHelper::collectionFromScope(cmd.collection(), connection()->context());
if (!collection.isValid()) {
return failureResponse("No such collection");
}
......@@ -53,7 +53,7 @@ bool CollectionModifyHandler::parseStream()
if (newParent.isValid() && collection.parentId() != newParent.id()
&& collection.resourceId() != newParent.resourceId()) {
inhibitor.inhibit();
ItemRetriever retriever(connection());
ItemRetriever retriever(connection(), connection()->context());
retriever.setCollection(collection, true);
retriever.setRetrieveFullPayload(true);
if (!retriever.exec()) {
......
......@@ -34,7 +34,7 @@ bool CollectionMoveHandler::parseStream()
{
const auto &cmd = Protocol::cmdCast<Protocol::MoveCollectionCommand>(m_command);
Collection source = HandlerHelper::collectionFromScope(cmd.collection(), connection());
Collection source = HandlerHelper::collectionFromScope(cmd.collection(), connection()->context());
if (!source.isValid()) {
return failureResponse(QStringLiteral("Invalid collection to move"));
}
......@@ -43,7 +43,7 @@ bool CollectionMoveHandler::parseStream()
if (cmd.destination().isEmpty()) {
target.setId(0);
} else {
target = HandlerHelper::collectionFromScope(cmd.destination(), connection());
target = HandlerHelper::collectionFromScope(cmd.destination(), connection()->context());
if (!target.isValid()) {
return failureResponse(QStringLiteral("Invalid destination collection"));
}
......@@ -56,7 +56,7 @@ bool CollectionMoveHandler::parseStream()
CacheCleanerInhibitor inhibitor;
// retrieve all not yet cached items of the source
ItemRetriever retriever(connection());
ItemRetriever retriever(connection(), connection()->context());
retriever.setCollection(source, true);
retriever.setRetrieveFullPayload(true);
if (!retriever.exec()) {
......
......@@ -33,7 +33,7 @@ bool CollectionStatsFetchHandler::parseStream()
{
const auto &cmd = Protocol::cmdCast<Protocol::FetchCollectionStatsCommand>(m_command);
const Collection col = HandlerHelper::collectionFromScope(cmd.collection(), connection());
const Collection col = HandlerHelper::collectionFromScope(cmd.collection(), connection()->context());
if (!col.isValid()) {
return failureResponse(QStringLiteral("No status for this folder"));
}
......
......@@ -101,7 +101,7 @@ bool ItemCopyHandler::parseStream()
return failureResponse(QStringLiteral("No items specified"));
}
mTargetCollection = HandlerHelper::collectionFromScope(cmd.destination(), connection());
mTargetCollection = HandlerHelper::collectionFromScope(cmd.destination(), connection()->context());
if (!mTargetCollection.isValid()) {
return failureResponse(QStringLiteral("No valid target specified"));
}
......@@ -111,7 +111,7 @@ bool ItemCopyHandler::parseStream()
CacheCleanerInhibitor inhibitor;
ItemRetriever retriever(connection());
ItemRetriever retriever(connection(), connection()->context());
retriever.setItemSet(cmd.items().uidSet());
retriever.setRetrieveFullPayload(true);
QObject::connect(&retriever, &ItemRetriever::itemsRetrieved,
......
......@@ -45,7 +45,7 @@ using namespace AkRanges;
bool ItemCreateHandler::buildPimItem(const Protocol::CreateItemCommand &cmd, PimItem &item,
Collection &parentCol)
{
parentCol = HandlerHelper::collectionFromScope(cmd.collection(), connection());
parentCol = HandlerHelper::collectionFromScope(cmd.collection(), connection()->context());
if (!parentCol.isValid()) {
return failureResponse(QStringLiteral("Invalid parent collection"));
}
......@@ -102,7 +102,7 @@ bool ItemCreateHandler::insertItem(const Protocol::CreateItemCommand &cmd, PimIt
const Scope tags = cmd.mergeModes() == Protocol::CreateItemCommand::None ? cmd.tags() : cmd.addedTags();
if (!tags.isEmpty()) {
const Tag::List tagList = HandlerHelper::tagsFromScope(tags, connection());
const Tag::List tagList = HandlerHelper::tagsFromScope(tags, connection()->context());
bool tagsChanged = false;
if (!storageBackend()->appendItemsTags({item}, tagList, &tagsChanged, false, parentCol, true)) {
return failureResponse(QStringLiteral("Unable to append item tags."));
......@@ -233,11 +233,11 @@ bool ItemCreateHandler::mergeItem(const Protocol::CreateItemCommand &cmd,
if (cmd.tags().isEmpty()) {
bool tagsAdded = false, tagsRemoved = false;
if (!cmd.addedTags().isEmpty()) {
const auto addedTags = HandlerHelper::tagsFromScope(cmd.addedTags(), connection());
const auto addedTags = HandlerHelper::tagsFromScope(cmd.addedTags(), connection()->context());
storageBackend()->appendItemsTags({currentItem}, addedTags, &tagsAdded, true, col, true);
}
if (!cmd.removedTags().isEmpty()) {
const Tag::List removedTags = HandlerHelper::tagsFromScope(cmd.removedTags(), connection());
const Tag::List removedTags = HandlerHelper::tagsFromScope(cmd.removedTags(), connection()->context());
storageBackend()->removeItemsTags({currentItem}, removedTags, &tagsRemoved, true);
}
......@@ -247,7 +247,7 @@ bool ItemCreateHandler::mergeItem(const Protocol::CreateItemCommand &cmd,
}
} else {
bool tagsChanged = false;
const auto tags = HandlerHelper::tagsFromScope(cmd.tags(), connection());
const auto tags = HandlerHelper::tagsFromScope(cmd.tags(), connection()->context());
storageBackend()->setItemsTags({currentItem}, tags, &tagsChanged, true);
if (tagsChanged) {
changedParts.insert(AKONADI_PARAM_TAGS);
......@@ -288,7 +288,7 @@ bool ItemCreateHandler::mergeItem(const Protocol::CreateItemCommand &cmd,
currentItem.setRev(qMax(newItem.rev(), currentItem.rev()) + 1);
currentItem.setAtime(QDateTime::currentDateTimeUtc());
// Only mark dirty when merged from application
currentItem.setDirty(!connection()->context()->resource().isValid());
currentItem.setDirty(!connection()->context().resource().isValid());
// Store all changes
if (!currentItem.update()) {
......
......@@ -34,10 +34,13 @@ bool ItemDeleteHandler::parseStream()
{
const auto &cmd = Protocol::cmdCast<Protocol::DeleteItemsCommand>(m_command);
connection()->context()->setScopeContext(cmd.scopeContext());
CommandContext context = connection()->context();
if (!context.setScopeContext(cmd.scopeContext())) {
return failureResponse(QStringLiteral("Invalid scope context"));
}
SelectQueryBuilder<PimItem> qb;
ItemQueryHelper::scopeToQuery(cmd.items(), connection()->context(), qb);
ItemQueryHelper::scopeToQuery(cmd.items(), context, qb);
DataStore *store = connection()->storageBackend();
Transaction transaction(store, QStringLiteral("REMOVE"));
......
......@@ -30,18 +30,19 @@ bool ItemFetchHandler::parseStream()
{
const auto &cmd = Protocol::cmdCast<Protocol::FetchItemsCommand>(m_command);
if (!connection()->context()->setScopeContext(cmd.scopeContext())) {
CommandContext context = connection()->context();
if (!context.setScopeContext(cmd.scopeContext())) {
return failureResponse(QStringLiteral("Invalid scope context"));
}
// We require context in case we do RID fetch
if (connection()->context()->isEmpty() && cmd.scope().scope() == Scope::Rid) {
if (context.isEmpty() && cmd.scope().scope() == Scope::Rid) {
return failureResponse(QStringLiteral("No FETCH context specified"));
}
CacheCleanerInhibitor inhibitor;
ItemFetchHelper fetchHelper(connection(), cmd.scope(), cmd.itemFetchScope(), cmd.tagFetchScope());
ItemFetchHelper fetchHelper(connection(), context, cmd.scope(), cmd.itemFetchScope(), cmd.tagFetchScope());
if (!fetchHelper.fetchItems()) {
return failureResponse(QStringLiteral("Failed to fetch items"));
}
......
......@@ -79,7 +79,7 @@ ItemFetchHelper::ItemFetchHelper(Connection *connection, const Scope &scope,
}
ItemFetchHelper::ItemFetchHelper(Connection *connection, CommandContext *context,
ItemFetchHelper::ItemFetchHelper(Connection *connection, const CommandContext &context,
const Scope &scope,
const Protocol::ItemFetchScope &itemFetchScope,
const Protocol::TagFetchScope &tagFetchScope)
......@@ -290,9 +290,9 @@ bool ItemFetchHelper::isScopeLocal(const Scope &scope)
qb.addJoin(QueryBuilder::LeftJoin, Resource::tableName(),
Collection::resourceIdFullColumnName(), Resource::idFullColumnName());
ItemQueryHelper::scopeToQuery(scope, mContext, qb);
if (mContext->resource().isValid()) {
if (mContext.resource().isValid()) {
qb.addValueCondition(Resource::nameFullColumnName(), Query::NotEquals,
mContext->resource().name());
mContext.resource().name());
}
if (!qb.exec()) {
......@@ -359,20 +359,20 @@ bool ItemFetchHelper::fetchItems(std::function<void(Protocol::FetchItemsResponse
// Prepare for a call to ItemRetriever::exec();
// From a resource perspective the only parts that can be fetched are payloads.
ItemRetriever retriever(mConnection);
ItemRetriever retriever(mConnection, mContext);
retriever.setScope(mScope);
retriever.setRetrieveParts(mItemFetchScope.requestedPayloads());
retriever.setRetrieveFullPayload(mItemFetchScope.fullPayload());
retriever.setChangedSince(mItemFetchScope.changedSince());
if (!retriever.exec() && !mItemFetchScope.ignoreErrors()) { // There we go, retrieve the missing parts from the resource.
if (mContext->resource().isValid()) {
if (mContext.resource().isValid()) {
throw HandlerException(QStringLiteral("Unable to fetch item from backend (collection %1, resource %2) : %3")
.arg(mContext->collectionId())
.arg(mContext->resource().id())
.arg(mContext.collectionId())
.arg(mContext.resource().id())
.arg(QString::fromLatin1(retriever.lastError())));
} else {
throw HandlerException(QStringLiteral("Unable to fetch item from backend (collection %1) : %2")
.arg(mContext->collectionId())
.arg(mContext.collectionId())
.arg(QString::fromLatin1(retriever.lastError())));
}
}
......@@ -707,11 +707,11 @@ void ItemFetchHelper::updateItemAccessTime()
void ItemFetchHelper::triggerOnDemandFetch()
{
if (mContext->collectionId() <= 0 || mItemFetchScope.cacheOnly()) {
if (mContext.collectionId() <= 0 || mItemFetchScope.cacheOnly()) {
return;
}
Collection collection = mContext->collection();
Collection collection = mContext.collection();
// HACK: don't trigger on-demand syncing if the resource is the one triggering it
if (mConnection->sessionId() == collection.resource().name().toLatin1()) {
......
......@@ -49,7 +49,7 @@ public:
ItemFetchHelper(Connection *connection, const Scope &scope,
const Protocol::ItemFetchScope &itemFetchScope,
const Protocol::TagFetchScope &tagFagScope);
ItemFetchHelper(Connection *connection, CommandContext *context, const Scope &scope,
ItemFetchHelper(Connection *connection, const CommandContext &context, const Scope &scope,
const Protocol::ItemFetchScope &itemFetchScope,
const Protocol::TagFetchScope &tagFetchScope);
......@@ -89,7 +89,7 @@ private:
private:
Connection *mConnection = nullptr;
CommandContext *mContext = nullptr;
const CommandContext &mContext;
QHash<Collection::Id, QVector<Protocol::Ancestor>> mAncestorCache;
Scope mScope;
Protocol::ItemFetchScope mItemFetchScope;
......
......@@ -37,7 +37,7 @@ bool ItemLinkHandler::parseStream()
{
const auto &cmd = Protocol::cmdCast<Protocol::LinkItemsCommand>(m_command);
const Collection collection = HandlerHelper::collectionFromScope(cmd.destination(), connection());
const Collection collection = HandlerHelper::collectionFromScope(cmd.destination(), connection()->context());
if (!collection.isVirtual()) {
return failureResponse(QStringLiteral("Can't link items to non-virtual collections"));
}
......
......@@ -96,7 +96,7 @@ bool ItemModifyHandler::deleteFlags(const PimItem::List &items, const QSet<QByte
bool ItemModifyHandler::replaceTags(const PimItem::List &item, const Scope &tags, bool &tagsChanged)
{
const Tag::List tagList = HandlerHelper::tagsFromScope(tags, connection());
const Tag::List tagList = HandlerHelper::tagsFromScope(tags, connection()->context());
if (!connection()->storageBackend()->setItemsTags(item, tagList, &tagsChanged)) {
qCWarning(AKONADISERVER_LOG) << "ItemModifyHandler::replaceTags: unable to replace tags";
return false;
......@@ -106,7 +106,7 @@ bool ItemModifyHandler::replaceTags(const PimItem::List &item, const Scope &tags
bool ItemModifyHandler::addTags(const PimItem::List &items, const Scope &tags, bool &tagsChanged)
{
const Tag::List tagList = HandlerHelper::tagsFromScope(tags, connection());
const Tag::List tagList = HandlerHelper::tagsFromScope(tags, connection()->context());
if (!connection()->storageBackend()->appendItemsTags(items, tagList, &tagsChanged)) {
qCWarning(AKONADISERVER_LOG) << "ItemModifyHandler::addTags: Unable to add new item tags";
return false;
......@@ -116,7 +116,7 @@ bool ItemModifyHandler::addTags(const PimItem::List &items, const Scope &tags, b
bool ItemModifyHandler::deleteTags(const PimItem::List &items, const Scope &tags, bool &tagsChanged)
{
const Tag::List tagList = HandlerHelper::tagsFromScope(tags, connection());
const Tag::List tagList = HandlerHelper::tagsFromScope(tags, connection()->context());
if (!connection()->storageBackend()->removeItemsTags(items, tagList, &tagsChanged)) {
qCWarning(AKONADISERVER_LOG) << "ItemModifyHandler::deleteTags: Unable to remove item tags";
return false;
......
......@@ -80,7 +80,7 @@ void ItemMoveHandler::itemsRetrieved(const QList<qint64> &ids)
item.setAtime(mtime);
item.setDatetime(mtime);
// if the resource moved itself, we assume it did so because the change happenned in the backend
if (connection()->context()->resource().id() != mDestination.resourceId()) {
if (connection()->context().resource().id() != mDestination.resourceId()) {
item.setDirty(true);
}
......@@ -136,7 +136,7 @@ bool ItemMoveHandler::parseStream()
{
const auto &cmd = Protocol::cmdCast<Protocol::MoveItemsCommand>(m_command);
mDestination = HandlerHelper::collectionFromScope(cmd.destination(), connection());
mDestination = HandlerHelper::collectionFromScope(cmd.destination(), connection()->context());
if (mDestination.isVirtual()) {
return failureResponse("Moving items into virtual collection is not allowed");
}
......@@ -144,9 +144,10 @@ bool ItemMoveHandler::parseStream()
return failureResponse("Invalid destination collection");
}
connection()->context()->setScopeContext(cmd.itemsContext());
CommandContext context = connection()->context();
context.setScopeContext(cmd.itemsContext());
if (cmd.items().scope() == Scope::Rid) {
if (!connection()->context()->collection().isValid()) {
if (!context.collection().isValid()) {
return failureResponse("RID move requires valid source collection");
}
}
......@@ -154,7 +155,7 @@ bool ItemMoveHandler::parseStream()
CacheCleanerInhibitor inhibitor;
// make sure all the items we want to move are in the cache
ItemRetriever retriever(connection());
ItemRetriever retriever(connection(), context);
retriever.setScope(cmd.items());
retriever.setRetrieveFullPayload(true);
QObject::connect(&retriever, &ItemRetriever::itemsRetrieved,
......
......@@ -60,7 +60,7 @@ bool RelationModifyHandler::parseStream()
return failureResponse("Invalid relation specified");
}
if (!cmd.remoteId().isEmpty() && !connection()->context()->resource().isValid()) {
if (!cmd.remoteId().isEmpty() && !connection()->context().resource().isValid()) {
return failureResponse("RemoteID can only be set by Resources");
}
......
......@@ -28,8 +28,10 @@ bool ResourceSelectHandler::parseStream()
{
const auto &cmd = Protocol::cmdCast<Protocol::SelectResourceCommand>(m_command);
CommandContext context = connection()->context();
if (cmd.resourceId().isEmpty()) {
connection()->context()->setResource(Resource());
context.setResource({});
connection()->setContext(context);
return successResponse<Protocol::SelectResourceResponse>();
}
......@@ -38,7 +40,8 @@ bool ResourceSelectHandler::parseStream()
return failureResponse(cmd.resourceId() % QStringLiteral(" is not a valid resource identifier"));
}
connection()->context()->setResource(res);
context.setResource(res);
connection()->setContext(context);
return successResponse<Protocol::SelectResourceResponse>();
}
......@@ -36,7 +36,7 @@ bool TagCreateHandler::parseStream()
{
const auto &cmd = Protocol::cmdCast<Protocol::CreateTagCommand>(m_command);
if (!cmd.remoteId().isEmpty() && !connection()->context()->resource().isValid()) {
if (!cmd.remoteId().isEmpty() && !connection()->context().resource().isValid()) {
return failureResponse(QStringLiteral("Only resources can create tags with remote ID"));
}
......@@ -93,7 +93,7 @@ bool TagCreateHandler::parseStream()
}
if (!cmd.remoteId().isEmpty()) {
const qint64 resourceId = connection()->context()->resource().id();
const qint64 resourceId = connection()->context().resource().id();
CountQueryBuilder qb(TagRemoteIdResourceRelation::tableName());
qb.addValueCondition(TagRemoteIdResourceRelation::tagIdColumn(), Query::Equals, tagId);
......
......@@ -90,11 +90,11 @@ QSqlQuery TagFetchHelper::buildTagQuery()
qb.addColumn(TagType::nameFullColumnName());
// Expose tag's remote ID only to resources
if (mFetchScope.fetchRemoteID() && mConnection->context()->resource().isValid()) {
if (mFetchScope.fetchRemoteID() && mConnection->context().resource().isValid()) {
qb.addColumn(TagRemoteIdResourceRelation::remoteIdFullColumnName());
Query::Condition joinCondition;
joinCondition.addValueCondition(TagRemoteIdResourceRelation::resourceIdFullColumnName(),
Query::Equals, mConnection->context()->resource().id());
Query::Equals, mConnection->context().resource().id());
joinCondition.addColumnCondition(TagRemoteIdResourceRelation::tagIdFullColumnName(),
Query::Equals, Tag::idFullColumnName());
qb.addJoin(QueryBuilder::LeftJoin, TagRemoteIdResourceRelation::tableName(), joinCondition);
......@@ -127,7 +127,6 @@ QMap<QByteArray, QByteArray> TagFetchHelper::fetchTagAttributes(qint64 tagId,
bool TagFetchHelper::fetchTags()
{
QSqlQuery tagQuery = buildTagQuery();
QSqlQuery attributeQuery;
if (!mFetchScope.fetchIdOnly()) {
......@@ -147,7 +146,7 @@ bool TagFetchHelper::fetchTags()
response.setParentId(tagQuery.