20 #include "aggregatedfetchscope.h" 21 #include <private/protocol_p.h> 22 #include <shared/akranges.h> 25 #include <QMutexLocker> 27 #define LOCKED_D(name) \ 29 QMutexLocker lock(&d->lock); 35 class AggregatedFetchScopePrivate
38 AggregatedFetchScopePrivate()
44 auto it = count.
find(value);
45 if (it == count.
end()) {
46 it = count.
insert(value, 0);
54 auto it = count.
find(value);
55 if (it == count.
end()) {
65 inline void updateBool(
bool newValue,
int &store)
67 store += newValue ? 1 : -1;
73 const auto added = newSet - oldSet;
74 for (
const auto &value : added) {
75 addToSet(value,
set, count);
77 const auto removed = oldSet - newSet;
78 for (
const auto &value : removed) {
79 removeFromSet(value,
set, count);
87 class AggregatedCollectionFetchScopePrivate :
public AggregatedFetchScopePrivate
98 class AggregatedTagFetchScopePrivate :
public AggregatedFetchScopePrivate
105 int fetchRemoteId = 0;
106 int doNotFetchAllAttributes = 0;
109 class AggregatedItemFetchScopePrivate :
public AggregatedFetchScopePrivate
112 mutable Protocol::ItemFetchScope mCachedScope;
113 mutable bool mCachedScopeValid =
false;
120 int ancestors[3] = { 0, 0, 0 };
123 int allAttributes = 0;
127 int ignoreErrors = 0;
132 int fetchRelations = 0;
143 AggregatedCollectionFetchScope::AggregatedCollectionFetchScope()
144 : d_ptr(new AggregatedCollectionFetchScopePrivate)
148 AggregatedCollectionFetchScope::~AggregatedCollectionFetchScope()
153 void AggregatedCollectionFetchScope::apply(
const Protocol::CollectionFetchScope &oldScope,
154 const Protocol::CollectionFetchScope &newScope)
156 LOCKED_D(AggregatedCollectionFetchScope)
158 if (newScope.includeStatistics() != oldScope.includeStatistics()) {
159 d->updateBool(newScope.includeStatistics(), d->fetchStats);
161 if (newScope.fetchIdOnly() != oldScope.fetchIdOnly()) {
162 d->updateBool(newScope.fetchIdOnly(), d->fetchIdOnly);
164 if (newScope.attributes() != oldScope.attributes()) {
165 d->applySet(oldScope.attributes(), newScope.attributes(), d->attrs, d->attrsCount);
171 LOCKED_D(
const AggregatedCollectionFetchScope)
175 bool AggregatedCollectionFetchScope::fetchIdOnly()
const 177 LOCKED_D(
const AggregatedCollectionFetchScope)
180 return d->fetchIdOnly == d->subscribers;
183 bool AggregatedCollectionFetchScope::fetchStatistics()
const 185 LOCKED_D(
const AggregatedCollectionFetchScope);
187 return d->fetchStats > 0;
190 void AggregatedCollectionFetchScope::addSubscriber()
192 LOCKED_D(AggregatedCollectionFetchScope)
196 void AggregatedCollectionFetchScope::removeSubscriber()
198 LOCKED_D(AggregatedCollectionFetchScope)
203 AggregatedItemFetchScope::AggregatedItemFetchScope()
204 : d_ptr(new AggregatedItemFetchScopePrivate)
208 AggregatedItemFetchScope::~AggregatedItemFetchScope()
213 void AggregatedItemFetchScope::apply(
const Protocol::ItemFetchScope &oldScope,
214 const Protocol::ItemFetchScope &newScope)
216 LOCKED_D(AggregatedItemFetchScope);
218 const auto newParts = newScope.requestedParts() | AkRanges::Actions::toQSet;
219 const auto oldParts = oldScope.requestedParts() | AkRanges::Actions::toQSet;
220 if (newParts != oldParts) {
221 d->applySet(oldParts, newParts, d->parts, d->partsCount);
223 if (newScope.ancestorDepth() != oldScope.ancestorDepth()) {
224 updateAncestorDepth(oldScope.ancestorDepth(), newScope.ancestorDepth());
226 if (newScope.cacheOnly() != oldScope.cacheOnly()) {
227 d->updateBool(newScope.cacheOnly(), d->cacheOnly);
229 if (newScope.fullPayload() != oldScope.fullPayload()) {
230 d->updateBool(newScope.fullPayload(), d->fullPayload);
232 if (newScope.allAttributes() != oldScope.allAttributes()) {
233 d->updateBool(newScope.allAttributes(), d->allAttributes);
235 if (newScope.fetchSize() != oldScope.fetchSize()) {
236 d->updateBool(newScope.fetchSize(), d->fetchSize);
238 if (newScope.fetchMTime() != oldScope.fetchMTime()) {
239 d->updateBool(newScope.fetchMTime(), d->fetchMTime);
241 if (newScope.fetchRemoteRevision() != oldScope.fetchRemoteRevision()) {
242 d->updateBool(newScope.fetchRemoteRevision(), d->fetchRRev);
244 if (newScope.ignoreErrors() != oldScope.ignoreErrors()) {
245 d->updateBool(newScope.ignoreErrors(), d->ignoreErrors);
247 if (newScope.fetchFlags() != oldScope.fetchFlags()) {
248 d->updateBool(newScope.fetchFlags(), d->fetchFlags);
250 if (newScope.fetchRemoteId() != oldScope.fetchRemoteId()) {
251 d->updateBool(newScope.fetchRemoteId(), d->fetchRID);
253 if (newScope.fetchGID() != oldScope.fetchGID()) {
254 d->updateBool(newScope.fetchGID(), d->fetchGID);
256 if (newScope.fetchTags() != oldScope.fetchTags()) {
257 d->updateBool(newScope.fetchTags(), d->fetchTags);
259 if (newScope.fetchRelations() != oldScope.fetchRelations()) {
260 d->updateBool(newScope.fetchRelations(), d->fetchRelations);
262 if (newScope.fetchVirtualReferences() != oldScope.fetchVirtualReferences()) {
263 d->updateBool(newScope.fetchVirtualReferences(), d->fetchVRefs);
266 d->mCachedScopeValid =
false;
271 LOCKED_D(
const AggregatedItemFetchScope);
272 if (d->mCachedScopeValid) {
273 return d->mCachedScope;
277 d->mCachedScope.setRequestedParts(d->parts | AkRanges::Actions::toQVector);
278 d->mCachedScope.setAncestorDepth(ancestorDepth());
280 d->mCachedScope.setFetch(ItemFetchScope::CacheOnly, cacheOnly());
281 d->mCachedScope.setFetch(ItemFetchScope::FullPayload, fullPayload());
282 d->mCachedScope.setFetch(ItemFetchScope::AllAttributes, allAttributes());
283 d->mCachedScope.setFetch(ItemFetchScope::Size, fetchSize());
284 d->mCachedScope.setFetch(ItemFetchScope::MTime, fetchMTime());
285 d->mCachedScope.setFetch(ItemFetchScope::RemoteRevision, fetchRemoteRevision());
286 d->mCachedScope.setFetch(ItemFetchScope::IgnoreErrors, ignoreErrors());
287 d->mCachedScope.setFetch(ItemFetchScope::Flags, fetchFlags());
288 d->mCachedScope.setFetch(ItemFetchScope::RemoteID, fetchRemoteId());
289 d->mCachedScope.setFetch(ItemFetchScope::GID, fetchGID());
290 d->mCachedScope.setFetch(ItemFetchScope::Tags, fetchTags());
291 d->mCachedScope.setFetch(ItemFetchScope::Relations, fetchRelations());
292 d->mCachedScope.setFetch(ItemFetchScope::VirtReferences, fetchVirtualReferences());
293 d->mCachedScopeValid =
true;
294 return d->mCachedScope;
299 LOCKED_D(
const AggregatedItemFetchScope)
303 ItemFetchScope::AncestorDepth AggregatedItemFetchScope::ancestorDepth()
const 305 LOCKED_D(
const AggregatedItemFetchScope)
308 return ItemFetchScope::AllAncestors;
309 }
else if (d->ancestors[ItemFetchScope::ParentAncestor] > 0) {
310 return ItemFetchScope::ParentAncestor;
312 return ItemFetchScope::NoAncestor;
316 void AggregatedItemFetchScope::updateAncestorDepth(ItemFetchScope::AncestorDepth oldDepth,
317 ItemFetchScope::AncestorDepth newDepth)
319 LOCKED_D(AggregatedItemFetchScope)
320 if (d->ancestors[oldDepth] > 0) {
321 --d->ancestors[oldDepth];
323 ++d->ancestors[newDepth];
326 bool AggregatedItemFetchScope::cacheOnly()
const 328 LOCKED_D(
const AggregatedItemFetchScope)
331 return d->cacheOnly == d->subscribers;
334 bool AggregatedItemFetchScope::fullPayload()
const 336 LOCKED_D(
const AggregatedItemFetchScope)
339 return d->fullPayload > 0;
342 bool AggregatedItemFetchScope::allAttributes()
const 344 LOCKED_D(
const AggregatedItemFetchScope)
347 return d->allAttributes > 0;
350 bool AggregatedItemFetchScope::fetchSize()
const 352 LOCKED_D(
const AggregatedItemFetchScope)
354 return d->fetchSize > 0;
357 bool AggregatedItemFetchScope::fetchMTime()
const 359 LOCKED_D(
const AggregatedItemFetchScope)
361 return d->fetchMTime > 0;
364 bool AggregatedItemFetchScope::fetchRemoteRevision()
const 366 LOCKED_D(
const AggregatedItemFetchScope)
368 return d->fetchRRev > 0;
371 bool AggregatedItemFetchScope::ignoreErrors()
const 373 LOCKED_D(
const AggregatedItemFetchScope)
376 return d->ignoreErrors == d->subscribers;
379 bool AggregatedItemFetchScope::fetchFlags()
const 381 LOCKED_D(
const AggregatedItemFetchScope)
383 return d->fetchFlags > 0;
386 bool AggregatedItemFetchScope::fetchRemoteId()
const 388 LOCKED_D(
const AggregatedItemFetchScope)
390 return d->fetchRID > 0;
393 bool AggregatedItemFetchScope::fetchGID()
const 395 LOCKED_D(
const AggregatedItemFetchScope)
397 return d->fetchGID > 0;
400 bool AggregatedItemFetchScope::fetchTags()
const 402 LOCKED_D(
const AggregatedItemFetchScope)
404 return d->fetchTags > 0;
407 bool AggregatedItemFetchScope::fetchRelations()
const 409 LOCKED_D(
const AggregatedItemFetchScope)
411 return d->fetchRelations > 0;
414 bool AggregatedItemFetchScope::fetchVirtualReferences()
const 416 LOCKED_D(
const AggregatedItemFetchScope)
418 return d->fetchVRefs > 0;
421 void AggregatedItemFetchScope::addSubscriber()
423 LOCKED_D(AggregatedItemFetchScope)
427 void AggregatedItemFetchScope::removeSubscriber()
429 LOCKED_D(AggregatedItemFetchScope)
436 AggregatedTagFetchScope::AggregatedTagFetchScope()
437 : d_ptr(new AggregatedTagFetchScopePrivate)
441 AggregatedTagFetchScope::~AggregatedTagFetchScope()
446 void AggregatedTagFetchScope::apply(
const Protocol::TagFetchScope &oldScope,
447 const Protocol::TagFetchScope &newScope)
449 LOCKED_D(AggregatedTagFetchScope)
451 if (newScope.fetchIdOnly() != oldScope.fetchIdOnly()) {
452 d->updateBool(newScope.fetchIdOnly(), d->fetchIdOnly);
454 if (newScope.fetchRemoteID() != oldScope.fetchRemoteID()) {
455 d->updateBool(newScope.fetchRemoteID(), d->fetchRemoteId);
457 if (newScope.fetchAllAttributes() != oldScope.fetchAllAttributes()) {
459 d->updateBool(!newScope.fetchAllAttributes(), d->doNotFetchAllAttributes);
461 if (newScope.attributes() != oldScope.attributes()) {
462 d->applySet(oldScope.attributes(), newScope.attributes(), d->attrs, d->attrsCount);
466 Protocol::TagFetchScope AggregatedTagFetchScope::toFetchScope()
const 468 Protocol::TagFetchScope tfs;
469 tfs.setFetchIdOnly(fetchIdOnly());
470 tfs.setFetchRemoteID(fetchRemoteId());
471 tfs.setFetchAllAttributes(fetchAllAttributes());
472 tfs.setAttributes(attributes());
476 bool AggregatedTagFetchScope::fetchIdOnly()
const 478 LOCKED_D(
const AggregatedTagFetchScope)
481 return d->fetchIdOnly == d->subscribers;
484 bool AggregatedTagFetchScope::fetchRemoteId()
const 486 LOCKED_D(
const AggregatedTagFetchScope)
487 return d->fetchRemoteId > 0;
490 bool AggregatedTagFetchScope::fetchAllAttributes()
const 492 LOCKED_D(
const AggregatedTagFetchScope)
494 return d->doNotFetchAllAttributes != d->subscribers;
499 LOCKED_D(
const AggregatedTagFetchScope)
503 void AggregatedTagFetchScope::addSubscriber()
505 LOCKED_D(AggregatedTagFetchScope)
509 void AggregatedTagFetchScope::removeSubscriber()
511 LOCKED_D(AggregatedTagFetchScope)
iterator insert(const Key &key, const T &value)
iterator erase(iterator pos)
Specifies which parts of an item should be fetched from the Akonadi storage.
iterator find(const Key &key)