Akonadi

intervalcheck.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Volker Krause <[email protected]>
3  SPDX-FileCopyrightText: 2014 Daniel Vr├ítil <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "intervalcheck.h"
9 #include "storage/datastore.h"
10 #include "storage/entity.h"
11 #include "storage/itemretrievalmanager.h"
12 
13 using namespace Akonadi::Server;
14 
15 static const int MINIMUM_AUTOSYNC_INTERVAL = 5; // minutes
16 static const int MINIMUM_COLTREESYNC_INTERVAL = 5; // minutes
17 
18 IntervalCheck::IntervalCheck(ItemRetrievalManager &itemRetrievalManager)
19  : CollectionScheduler(QStringLiteral("IntervalCheck"), QThread::IdlePriority)
20  , mItemRetrievalManager(itemRetrievalManager)
21 {
22 }
23 
24 IntervalCheck::~IntervalCheck()
25 {
26  quitThread();
27 }
28 
29 void IntervalCheck::requestCollectionSync(const Collection &collection)
30 {
32  this,
33  [this, collection]() {
34  collectionExpired(collection);
35  },
37 }
38 
39 int IntervalCheck::collectionScheduleInterval(const Collection &collection)
40 {
41  return collection.cachePolicyCheckInterval();
42 }
43 
44 bool IntervalCheck::hasChanged(const Collection &collection, const Collection &changed)
45 {
46  return collection.cachePolicyCheckInterval() != changed.cachePolicyCheckInterval() || collection.enabled() != changed.enabled()
47  || collection.syncPref() != changed.syncPref();
48 }
49 
50 bool IntervalCheck::shouldScheduleCollection(const Collection &collection)
51 {
52  return collection.cachePolicyCheckInterval() > 0
53  && ((collection.syncPref() == Collection::True) || ((collection.syncPref() == Collection::Undefined) && collection.enabled()));
54 }
55 
56 void IntervalCheck::collectionExpired(const Collection &collection)
57 {
59 
60  if (collection.parentId() == 0) {
61  const QString resourceName = collection.resource().name();
62 
63  const int interval = qMax(MINIMUM_COLTREESYNC_INTERVAL, collection.cachePolicyCheckInterval());
64 
65  const QDateTime lastExpectedCheck = now.addSecs(interval * -60);
66  if (!mLastCollectionTreeSyncs.contains(resourceName) || mLastCollectionTreeSyncs.value(resourceName) < lastExpectedCheck) {
67  mLastCollectionTreeSyncs.insert(resourceName, now);
68  mItemRetrievalManager.triggerCollectionTreeSync(resourceName);
69  }
70  }
71 
72  // now on to the actual collection syncing
73  const int interval = qMax(MINIMUM_AUTOSYNC_INTERVAL, collection.cachePolicyCheckInterval());
74 
75  const QDateTime lastExpectedCheck = now.addSecs(interval * -60);
76  if (mLastChecks.contains(collection.id()) && mLastChecks.value(collection.id()) > lastExpectedCheck) {
77  return;
78  }
79  mLastChecks.insert(collection.id(), now);
80  mItemRetrievalManager.triggerCollectionSync(collection.resource().name(), collection.id());
81 }
QDateTime addSecs(qint64 s) const const
QDateTime currentDateTime()
Represents a collection of PIM items.
Definition: collection.h:61
Manages and processes item retrieval requests.
QueuedConnection
bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericReturnArgument ret, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.