Akonadi

intervalcheck.cpp
1 /*
2  Copyright (c) 2008 Volker Krause <[email protected]>
3  Copyright (C) 2014 Daniel Vrátil <[email protected]>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #include "intervalcheck.h"
22 #include "storage/datastore.h"
23 #include "storage/itemretrievalmanager.h"
24 #include "storage/entity.h"
25 
26 using namespace Akonadi::Server;
27 
28 static const int MINIMUM_AUTOSYNC_INTERVAL = 5; // minutes
29 static const int MINIMUM_COLTREESYNC_INTERVAL = 5; // minutes
30 
31 IntervalCheck::IntervalCheck(ItemRetrievalManager &itemRetrievalManager)
32  : CollectionScheduler(QStringLiteral("IntervalCheck"), QThread::IdlePriority)
33  , mItemRetrievalManager(itemRetrievalManager)
34 {
35 }
36 
37 IntervalCheck::~IntervalCheck()
38 {
39  quitThread();
40 }
41 
42 void IntervalCheck::requestCollectionSync(const Collection &collection)
43 {
44  QMetaObject::invokeMethod(this, [this, collection]() { collectionExpired(collection); }, Qt::QueuedConnection);
45 }
46 
47 int IntervalCheck::collectionScheduleInterval(const Collection &collection)
48 {
49  return collection.cachePolicyCheckInterval();
50 }
51 
52 bool IntervalCheck::hasChanged(const Collection &collection, const Collection &changed)
53 {
54  return collection.cachePolicyCheckInterval() != changed.cachePolicyCheckInterval()
55  || collection.enabled() != changed.enabled()
56  || collection.syncPref() != changed.syncPref();
57 }
58 
59 bool IntervalCheck::shouldScheduleCollection(const Collection &collection)
60 {
61  return collection.cachePolicyCheckInterval() > 0
62  && ((collection.syncPref() == Collection::True) || ((collection.syncPref() == Collection::Undefined) && collection.enabled()));
63 }
64 
65 void IntervalCheck::collectionExpired(const Collection &collection)
66 {
68 
69  if (collection.parentId() == 0) {
70  const QString resourceName = collection.resource().name();
71 
72  const int interval = qMax(MINIMUM_COLTREESYNC_INTERVAL, collection.cachePolicyCheckInterval());
73 
74  const QDateTime lastExpectedCheck = now.addSecs(interval * -60);
75  if (!mLastCollectionTreeSyncs.contains(resourceName) || mLastCollectionTreeSyncs.value(resourceName) < lastExpectedCheck) {
76  mLastCollectionTreeSyncs.insert(resourceName, now);
77  mItemRetrievalManager.triggerCollectionTreeSync(resourceName);
78  }
79  }
80 
81  // now on to the actual collection syncing
82  const int interval = qMax(MINIMUM_AUTOSYNC_INTERVAL, collection.cachePolicyCheckInterval());
83 
84  const QDateTime lastExpectedCheck = now.addSecs(interval * -60);
85  if (mLastChecks.contains(collection.id()) && mLastChecks.value(collection.id()) > lastExpectedCheck) {
86  return;
87  }
88  mLastChecks.insert(collection.id(), now);
89  mItemRetrievalManager.triggerCollectionSync(collection.resource().name(), collection.id());
90 }
int cachePolicyCheckInterval() const
Returns the value of the cachePolicyCheckInterval column of this record.
Definition: entities.cpp:1533
Resource resource() const
Retrieve the Resource record referred to by the resourceId column of this record. ...
qint64 parentId() const
Returns the value of the parentId column of this record.
Definition: entities.cpp:1442
Manages and processes item retrieval requests.
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)
QDateTime currentDateTime()
Collection::Tristate syncPref() const
Returns the value of the syncPref column of this record.
Definition: entities.cpp:1481
bool enabled() const
Returns the value of the enabled column of this record.
QDateTime addSecs(qint64 s) const const
QString name() const
Returns the value of the name column of this record.
Definition: entities.cpp:545
Representation of a record in the Collection table.
Definition: entities.h:451
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue May 26 2020 22:46:20 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.