diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-01 01:03:18 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-03-01 01:05:01 +0100 |
commit | c08c329580a6f5e5da1ebba931461e7e7e47ba72 (patch) | |
tree | a60e2c3c5d189d554bd69de600d96d024b49e864 /common/store.cpp | |
parent | 4be4995e7b430226b763f06a051fd0e5cbf398ab (diff) | |
download | sink-c08c329580a6f5e5da1ebba931461e7e7e47ba72.tar.gz sink-c08c329580a6f5e5da1ebba931461e7e7e47ba72.zip |
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.
Diffstat (limited to 'common/store.cpp')
-rw-r--r-- | common/store.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
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<typename AggregatingResultEmitter<typename DomainType::Ptr>::Ptr, typenam | |||
96 | SinkTraceCtx(ctx) << "Listening for new resources."; | 96 | SinkTraceCtx(ctx) << "Listening for new resources."; |
97 | resourceQuery.setFlags(Query::LiveQuery); | 97 | resourceQuery.setFlags(Query::LiveQuery); |
98 | } | 98 | } |
99 | resourceQuery.setFilter(query.getResourceFilter()); | 99 | |
100 | //Filter resources by available content types (unless the query already specifies a capability filter) | ||
101 | auto resourceFilter = query.getResourceFilter(); | ||
102 | if (!resourceFilter.propertyFilter.contains(ApplicationDomain::SinkResource::Capabilities::name)) { | ||
103 | resourceFilter.propertyFilter.insert(ApplicationDomain::SinkResource::Capabilities::name, Query::Comparator{ApplicationDomain::getTypeName<DomainType>(), Query::Comparator::Contains}); | ||
104 | } | ||
105 | resourceQuery.setFilter(resourceFilter); | ||
106 | |||
100 | auto result = facade->load(resourceQuery, resourceCtx); | 107 | auto result = facade->load(resourceQuery, resourceCtx); |
101 | auto emitter = result.second; | 108 | auto emitter = result.second; |
102 | emitter->onAdded([query, aggregatingEmitter, resourceCtx](const ApplicationDomain::SinkResource::Ptr &resource) { | 109 | emitter->onAdded([=](const ApplicationDomain::SinkResource::Ptr &resource) { |
103 | SinkTraceCtx(resourceCtx) << "Found new resources: " << resource->identifier(); | 110 | SinkTraceCtx(resourceCtx) << "Found new resources: " << resource->identifier(); |
104 | const auto resourceType = ResourceConfig::getResourceType(resource->identifier()); | 111 | const auto resourceType = ResourceConfig::getResourceType(resource->identifier()); |
105 | Q_ASSERT(!resourceType.isEmpty()); | 112 | Q_ASSERT(!resourceType.isEmpty()); |
106 | queryResource<DomainType>(resourceType, resource->identifier(), query, aggregatingEmitter, resourceCtx).exec(); | 113 | queryResource<DomainType>(resourceType, resource->identifier(), query, aggregatingEmitter, ctx).exec(); |
107 | }); | 114 | }); |
108 | emitter->onModified([](const ApplicationDomain::SinkResource::Ptr &) { | 115 | emitter->onModified([](const ApplicationDomain::SinkResource::Ptr &) { |
109 | }); | 116 | }); |