58 lines
2.3 KiB
Diff
58 lines
2.3 KiB
Diff
From 55dc6d141a20e2438308214ab60c18e282dd7b43 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Dan=20Vr=C3=A1til?= <dvratil@redhat.com>
|
|
Date: Mon, 8 Dec 2014 10:33:51 +0100
|
|
Subject: [PATCH 25/30] Avoid repeated calls to PimItem::flags() and
|
|
PimItem::tags()
|
|
|
|
The queries results are not cached, so each call to those methods runs an SQL
|
|
query. At least in case of flags, this reduced the number of queries to one
|
|
query per changed item.
|
|
---
|
|
server/src/storage/datastore.cpp | 10 ++++++----
|
|
1 file changed, 6 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/server/src/storage/datastore.cpp b/server/src/storage/datastore.cpp
|
|
index c9fa0c3..035395e 100644
|
|
--- a/server/src/storage/datastore.cpp
|
|
+++ b/server/src/storage/datastore.cpp
|
|
@@ -220,7 +220,8 @@ bool DataStore::setItemsFlags( const PimItem::List &items, const QVector<Flag> &
|
|
setBoolPtr( flagsChanged, false );
|
|
|
|
Q_FOREACH ( const PimItem &item, items ) {
|
|
- Q_FOREACH ( const Flag &flag, item.flags() ) {
|
|
+ const Flag::List itemFlags = item.flags();
|
|
+ Q_FOREACH ( const Flag &flag, itemFlags ) {
|
|
if ( !flags.contains( flag ) ) {
|
|
removedFlags << flag.name().toLatin1();
|
|
Query::Condition cond;
|
|
@@ -231,7 +232,7 @@ bool DataStore::setItemsFlags( const PimItem::List &items, const QVector<Flag> &
|
|
}
|
|
|
|
Q_FOREACH ( const Flag &flag, flags ) {
|
|
- if ( !item.flags().contains( flag ) ) {
|
|
+ if ( !itemFlags.contains( flag ) ) {
|
|
addedFlags << flag.name().toLatin1();
|
|
insIds << item.id();
|
|
insFlags << flag.id();
|
|
@@ -414,7 +415,8 @@ bool DataStore::setItemsTags( const PimItem::List &items, const Tag::List &tags,
|
|
setBoolPtr( tagsChanged, false );
|
|
|
|
Q_FOREACH ( const PimItem &item, items ) {
|
|
- Q_FOREACH ( const Tag &tag, item.tags() ) {
|
|
+ const Tag::List itemTags = item.tags();
|
|
+ Q_FOREACH ( const Tag &tag, itemTags ) {
|
|
if ( !tags.contains( tag ) ) {
|
|
// Remove tags from items that had it set
|
|
removedTags << tag.id();
|
|
@@ -426,7 +428,7 @@ bool DataStore::setItemsTags( const PimItem::List &items, const Tag::List &tags,
|
|
}
|
|
|
|
Q_FOREACH ( const Tag &tag, tags ) {
|
|
- if ( !item.tags().contains( tag ) ) {
|
|
+ if ( !itemTags.contains( tag ) ) {
|
|
// Add tags to items that did not have the tag
|
|
addedTags << tag.id();
|
|
insIds << item.id();
|
|
--
|
|
2.1.0
|
|
|