]>
Commit | Line | Data |
---|---|---|
8a8f9fb3 AM |
1 | From ac118e12fca25826340b6c8561939be19c4b7170 Mon Sep 17 00:00:00 2001 |
2 | From: =?UTF-8?q?Dan=20Vr=C3=A1til?= <dvratil@redhat.com> | |
3 | Date: Mon, 8 Dec 2014 13:55:58 +0100 | |
4 | Subject: [PATCH 27/30] Minor improvements in StatisticsCache as suggested by | |
5 | Millian | |
6 | ||
7 | * rename instance() to self() | |
8 | * first call self() from main thread to avoid having mutex | |
9 | * use CountQueryBuilder | |
10 | --- | |
11 | server/src/akonadi.cpp | 4 +++- | |
12 | server/src/handler/select.cpp | 2 +- | |
13 | server/src/handler/status.cpp | 2 +- | |
14 | server/src/handlerhelper.cpp | 2 +- | |
15 | server/src/storage/collectionstatistics.cpp | 10 ++-------- | |
16 | server/src/storage/collectionstatistics.h | 2 +- | |
17 | server/src/storage/notificationcollector.cpp | 10 +++++----- | |
18 | 7 files changed, 14 insertions(+), 18 deletions(-) | |
19 | ||
20 | diff --git a/server/src/akonadi.cpp b/server/src/akonadi.cpp | |
21 | index 5369320..faef3a5 100644 | |
22 | --- a/server/src/akonadi.cpp | |
23 | +++ b/server/src/akonadi.cpp | |
24 | @@ -35,6 +35,7 @@ | |
25 | #include "utils.h" | |
26 | #include "debuginterface.h" | |
27 | #include "storage/itemretrievalthread.h" | |
28 | +#include "storage/collectionstatistics.h" | |
29 | #include "preprocessormanager.h" | |
30 | #include "search/searchmanager.h" | |
31 | #include "search/searchtaskmanagerthread.h" | |
32 | @@ -169,6 +170,8 @@ bool AkonadiServer::init() | |
33 | new DebugInterface( this ); | |
34 | ResourceManager::self(); | |
35 | ||
36 | + CollectionStatistics::self(); | |
37 | + | |
38 | // Initialize the preprocessor manager | |
39 | PreprocessorManager::init(); | |
40 | ||
41 | @@ -194,7 +197,6 @@ bool AkonadiServer::init() | |
42 | mAgentSearchManagerThread = new SearchTaskManagerThread( this ); | |
43 | mAgentSearchManagerThread->start(); | |
44 | ||
45 | - | |
46 | const QStringList searchManagers = settings.value( QLatin1String( "Search/Manager" ), | |
47 | QStringList() << QLatin1String( "Nepomuk" ) | |
48 | << QLatin1String( "Agent" ) ).toStringList(); | |
49 | diff --git a/server/src/handler/select.cpp b/server/src/handler/select.cpp | |
50 | index f1ecc44..a94d971 100644 | |
51 | --- a/server/src/handler/select.cpp | |
52 | +++ b/server/src/handler/select.cpp | |
53 | @@ -97,7 +97,7 @@ bool Select::parseStream() | |
54 | response.setString( "FLAGS (" + Flag::joinByName( Flag::retrieveAll(), QLatin1String( " " ) ).toLatin1() + ")" ); | |
55 | Q_EMIT responseAvailable( response ); | |
56 | ||
57 | - const CollectionStatistics::Statistics stats = CollectionStatistics::instance()->statistics(col); | |
58 | + const CollectionStatistics::Statistics stats = CollectionStatistics::self()->statistics(col); | |
59 | if ( stats.count == -1 ) { | |
60 | return failureResponse( "Unable to determine item count" ); | |
61 | } | |
62 | diff --git a/server/src/handler/status.cpp b/server/src/handler/status.cpp | |
63 | index 283532c..5fc9bb1 100644 | |
64 | --- a/server/src/handler/status.cpp | |
65 | +++ b/server/src/handler/status.cpp | |
66 | @@ -63,7 +63,7 @@ bool Status::parseStream() | |
67 | // Responses: | |
68 | // REQUIRED untagged responses: STATUS | |
69 | ||
70 | - const CollectionStatistics::Statistics &stats = CollectionStatistics::instance()->statistics(col); | |
71 | + const CollectionStatistics::Statistics &stats = CollectionStatistics::self()->statistics(col); | |
72 | if (stats.count == -1) { | |
73 | return failureResponse( "Failed to query statistics." ); | |
74 | } | |
75 | diff --git a/server/src/handlerhelper.cpp b/server/src/handlerhelper.cpp | |
76 | index 39583ce..a88bc6e 100644 | |
77 | --- a/server/src/handlerhelper.cpp | |
78 | +++ b/server/src/handlerhelper.cpp | |
79 | @@ -166,7 +166,7 @@ QByteArray HandlerHelper::collectionToByteArray( const Collection &col, bool hid | |
80 | b += " " AKONADI_PARAM_VIRTUAL " " + QByteArray::number( col.isVirtual() ) + ' '; | |
81 | ||
82 | if ( includeStatistics ) { | |
83 | - const CollectionStatistics::Statistics &stats = CollectionStatistics::instance()->statistics(col); | |
84 | + const CollectionStatistics::Statistics &stats = CollectionStatistics::self()->statistics(col); | |
85 | if (stats.count > -1) { | |
86 | b += AKONADI_ATTRIBUTE_MESSAGES " " + QByteArray::number( stats.count ) + ' '; | |
87 | b += AKONADI_ATTRIBUTE_UNSEEN " "; | |
88 | diff --git a/server/src/storage/collectionstatistics.cpp b/server/src/storage/collectionstatistics.cpp | |
89 | index b2c6915..7307956 100644 | |
90 | --- a/server/src/storage/collectionstatistics.cpp | |
91 | +++ b/server/src/storage/collectionstatistics.cpp | |
92 | @@ -31,14 +31,11 @@ using namespace Akonadi::Server; | |
93 | ||
94 | CollectionStatistics *CollectionStatistics::sInstance = 0; | |
95 | ||
96 | -CollectionStatistics* CollectionStatistics::instance() | |
97 | +CollectionStatistics* CollectionStatistics::self() | |
98 | { | |
99 | - static QMutex lock; | |
100 | - lock.lock(); | |
101 | if (sInstance == 0) { | |
102 | sInstance = new CollectionStatistics(); | |
103 | } | |
104 | - lock.unlock(); | |
105 | return sInstance; | |
106 | } | |
107 | ||
108 | @@ -60,11 +57,8 @@ const CollectionStatistics::Statistics& CollectionStatistics::statistics(const C | |
109 | ||
110 | CollectionStatistics::Statistics CollectionStatistics::getCollectionStatistics(const Collection &col) | |
111 | { | |
112 | - QueryBuilder qb(PimItem::tableName()); | |
113 | // COUNT(DISTINCT PimItemTable.id) | |
114 | - qb.addAggregation(QString::fromLatin1("DISTINCT %1") | |
115 | - .arg(PimItem::idFullColumnName()), | |
116 | - QLatin1String("count")); | |
117 | + CountQueryBuilder qb(PimItem::tableName(), PimItem::idFullColumnName(), CountQueryBuilder::Distinct); | |
118 | // SUM(PimItemTable.size) | |
119 | qb.addAggregation(PimItem::sizeFullColumnName(), QLatin1String("sum")); | |
120 | // SUM(CASE WHEN FlagTable.name IN ('\SEEN', '$IGNORED') THEN 1 ELSE 0 END) | |
121 | diff --git a/server/src/storage/collectionstatistics.h b/server/src/storage/collectionstatistics.h | |
122 | index 2c0af6a..a0b9f24 100644 | |
123 | --- a/server/src/storage/collectionstatistics.h | |
124 | +++ b/server/src/storage/collectionstatistics.h | |
125 | @@ -50,7 +50,7 @@ public: | |
126 | qint64 read; | |
127 | }; | |
128 | ||
129 | - static CollectionStatistics* instance(); | |
130 | + static CollectionStatistics* self(); | |
131 | ||
132 | const Statistics& statistics(const Collection &col); | |
133 | void invalidateCollection(const Collection &col); | |
134 | diff --git a/server/src/storage/notificationcollector.cpp b/server/src/storage/notificationcollector.cpp | |
135 | index dbc7883..7ed255c 100644 | |
136 | --- a/server/src/storage/notificationcollector.cpp | |
137 | +++ b/server/src/storage/notificationcollector.cpp | |
138 | @@ -134,7 +134,7 @@ void NotificationCollector::collectionChanged( const Collection &collection, | |
139 | if ( AkonadiServer::instance()->intervalChecker() ) { | |
140 | AkonadiServer::instance()->intervalChecker()->collectionAdded( collection.id() ); | |
141 | } | |
142 | - CollectionStatistics::instance()->invalidateCollection(collection); | |
143 | + CollectionStatistics::self()->invalidateCollection(collection); | |
144 | collectionNotification( NotificationMessageV2::Modify, collection, collection.parentId(), -1, resource, changes.toSet() ); | |
145 | } | |
146 | ||
147 | @@ -161,7 +161,7 @@ void NotificationCollector::collectionRemoved( const Collection &collection, | |
148 | if ( AkonadiServer::instance()->intervalChecker() ) { | |
149 | AkonadiServer::instance()->intervalChecker()->collectionRemoved( collection.id() ); | |
150 | } | |
151 | - CollectionStatistics::instance()->invalidateCollection(collection); | |
152 | + CollectionStatistics::self()->invalidateCollection(collection); | |
153 | ||
154 | collectionNotification( NotificationMessageV2::Remove, collection, collection.parentId(), -1, resource ); | |
155 | } | |
156 | @@ -187,7 +187,7 @@ void NotificationCollector::collectionUnsubscribed( const Collection &collection | |
157 | if ( AkonadiServer::instance()->intervalChecker() ) { | |
158 | AkonadiServer::instance()->intervalChecker()->collectionRemoved( collection.id() ); | |
159 | } | |
160 | - CollectionStatistics::instance()->invalidateCollection(collection); | |
161 | + CollectionStatistics::self()->invalidateCollection(collection); | |
162 | ||
163 | collectionNotification( NotificationMessageV2::Unsubscribe, collection, collection.parentId(), -1, resource, QSet<QByteArray>() ); | |
164 | } | |
165 | @@ -288,7 +288,7 @@ void NotificationCollector::itemNotification( NotificationMessageV2::Operation o | |
166 | copy.setParentCollection( iter.key() ); | |
167 | copy.setResource( resource ); | |
168 | ||
169 | - CollectionStatistics::instance()->invalidateCollection(Collection::retrieveById(iter.key())); | |
170 | + CollectionStatistics::self()->invalidateCollection(Collection::retrieveById(iter.key())); | |
171 | dispatchNotification( copy ); | |
172 | } | |
173 | ||
174 | @@ -311,7 +311,7 @@ void NotificationCollector::itemNotification( NotificationMessageV2::Operation o | |
175 | } | |
176 | msg.setResource( res ); | |
177 | ||
178 | - CollectionStatistics::instance()->invalidateCollection(col); | |
179 | + CollectionStatistics::self()->invalidateCollection(col); | |
180 | dispatchNotification( msg ); | |
181 | } | |
182 | ||
183 | -- | |
184 | 2.1.0 | |
185 |