Akonadi

server/storage/collectionstatistics.h
1 /*
2  * SPDX-FileCopyrightText: 2014 Daniel Vr├ítil <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 
8 #pragma once
9 
10 
11 #include <QHash>
12 #include <QMutex>
13 
14 namespace Akonadi
15 {
16 namespace Server
17 {
18 class QueryBuilder;
19 class Collection;
20 
21 /**
22  * Provides cache for collection statistics
23  *
24  * Collection statistics are requested very often, so to take some load from the
25  * database we cache the results until the statistics are invalidated (see
26  * NotificationCollector, which takes care for invalidating the statistics).
27  *
28  * The cache (together with optimization of the actual SQL query) seems to
29  * massively improve initial folder listing on system start (when IO and CPU loads
30  * are very high).
31  */
33 {
34 public:
35  struct Statistics {
36  qint64 count;
37  qint64 size;
38  qint64 read;
39  };
40 
41  explicit CollectionStatistics(bool prefetch = true);
42  virtual ~CollectionStatistics() = default;
43 
44  Statistics statistics(const Collection &col);
45 
46  void itemAdded(const Collection &col, qint64 size, bool seen);
47  void itemsSeenChanged(const Collection &col, qint64 seenCount);
48 
49  void invalidateCollection(const Collection &col);
50 
51  void expireCache();
52 
53 protected:
54  QueryBuilder prepareGenericQuery();
55 
56  virtual Statistics calculateCollectionStatistics(const Collection &col);
57 
58  QMutex mCacheLock;
60 };
61 
62 } // namespace Server
63 } // namespace Akonadi
64 
Represents a collection of PIM items.
Definition: collection.h:61
Provides cache for collection statistics.
Helper class to construct arbitrary SQL queries.
Definition: querybuilder.h:31
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:45 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.