From c08c329580a6f5e5da1ebba931461e7e7e47ba72 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 1 Mar 2017 01:03:18 +0100 Subject: Filter resources by the types they support. This avoid uselessly querying resources only to discover that they don't have a facade for the type. --- common/domain/applicationdomaintype.h | 2 ++ common/store.cpp | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'common') diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index fee6344..be04db9 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h @@ -418,6 +418,8 @@ struct SINK_EXPORT ImapResource { namespace ResourceCapabilities { namespace Mail { + static constexpr const char *mail = "mail"; + static constexpr const char *folder = "folder"; static constexpr const char *storage = "mail.storage"; static constexpr const char *drafts = "mail.drafts"; static constexpr const char *sent = "mail.sent"; diff --git a/common/store.cpp b/common/store.cpp index 9550d3e..1c8620b 100644 --- a/common/store.cpp +++ b/common/store.cpp @@ -96,14 +96,21 @@ QPair::Ptr, typenam SinkTraceCtx(ctx) << "Listening for new resources."; resourceQuery.setFlags(Query::LiveQuery); } - resourceQuery.setFilter(query.getResourceFilter()); + + //Filter resources by available content types (unless the query already specifies a capability filter) + auto resourceFilter = query.getResourceFilter(); + if (!resourceFilter.propertyFilter.contains(ApplicationDomain::SinkResource::Capabilities::name)) { + resourceFilter.propertyFilter.insert(ApplicationDomain::SinkResource::Capabilities::name, Query::Comparator{ApplicationDomain::getTypeName(), Query::Comparator::Contains}); + } + resourceQuery.setFilter(resourceFilter); + auto result = facade->load(resourceQuery, resourceCtx); auto emitter = result.second; - emitter->onAdded([query, aggregatingEmitter, resourceCtx](const ApplicationDomain::SinkResource::Ptr &resource) { + emitter->onAdded([=](const ApplicationDomain::SinkResource::Ptr &resource) { SinkTraceCtx(resourceCtx) << "Found new resources: " << resource->identifier(); const auto resourceType = ResourceConfig::getResourceType(resource->identifier()); Q_ASSERT(!resourceType.isEmpty()); - queryResource(resourceType, resource->identifier(), query, aggregatingEmitter, resourceCtx).exec(); + queryResource(resourceType, resource->identifier(), query, aggregatingEmitter, ctx).exec(); }); emitter->onModified([](const ApplicationDomain::SinkResource::Ptr &) { }); -- cgit v1.2.3