[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9
Maximiliano Curia
maxy at moszumanska.debian.org
Mon May 9 09:07:36 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=024f204
The following commit has been merged in the master branch:
commit 024f2046c462150c818121d9cf96173cea495959
Author: Vishesh Handa <me at vhanda.in>
Date: Thu May 30 23:41:28 2013 +0530
Create and cache the contact groups
Earlier, if a group contained more than one contact then it the contact
group was created that many times cause a new SimpleResource was created
each time.
With this method we cache the contact groups so that they are only
created once, and once they have been created we do not unnecessarily
send a new SimpleResource to get merged into the existing contact group.
REVIEW: 110739
---
kpeople/nepomuk-feeder/nepomuk-storage.cpp | 50 +++++++++++++++++++++++++-----
kpeople/nepomuk-feeder/nepomuk-storage.h | 3 ++
2 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/kpeople/nepomuk-feeder/nepomuk-storage.cpp b/kpeople/nepomuk-feeder/nepomuk-storage.cpp
index adee609..01725d8 100644
--- a/kpeople/nepomuk-feeder/nepomuk-storage.cpp
+++ b/kpeople/nepomuk-feeder/nepomuk-storage.cpp
@@ -641,6 +641,48 @@ void NepomukStorage::setContactAlias(const QString &path, const QString &id, con
fireGraphTimer();
}
+QUrl NepomukStorage::findGroup(const QString& groupName)
+{
+ QHash< QString, QUrl >::const_iterator fit = m_groupCache.constFind( groupName );
+ if (fit != m_groupCache.constEnd()) {
+ return fit.value();
+ }
+
+ const QString query = QString::fromLatin1("select ?g where { ?g nco:contactGroupName %1 . } LIMIT 1")
+ .arg(Soprano::Node::literalToN3(groupName));
+
+ Soprano::Model* model = Nepomuk2::ResourceManager::instance()->mainModel();
+ Soprano::QueryResultIterator iter = model->executeQuery( query,
+ Soprano::Query::QueryLanguageSparqlNoInference );
+
+ if (iter.next()) {
+ const QUrl uri = iter[0].uri();
+ m_groupCache.insert(groupName, uri);
+ return uri;
+ }
+
+ Nepomuk2::SimpleResource groupRes;
+ groupRes.addType(NCO::ContactGroup());
+ groupRes.setProperty(NCO::contactGroupName(), groupName);
+
+ Nepomuk2::SimpleResourceGraph graph;
+ graph << groupRes;
+
+ QHash<QUrl, QVariant> additional;
+ additional.insert(RDF::type(), NRL::DiscardableInstanceBase());
+
+ Nepomuk2::StoreResourcesJob *job = Nepomuk2::storeResources(graph, Nepomuk2::IdentifyNew,
+ Nepomuk2::NoStoreResourcesFlags,
+ additional);
+ // This is blocking, but the code is much easier this way
+ job->exec();
+
+ const QUrl uri = job->mappings().value(groupRes.uri());
+ m_groupCache.insert(groupName, uri);
+ return uri;
+}
+
+
void NepomukStorage::setContactGroups(const QString &path,
const QString &id,
const QStringList &groups)
@@ -660,15 +702,9 @@ void NepomukStorage::setContactGroups(const QString &path,
return;
}
- //FIXME: Ideally cache all the group uris
QVariantList groupUris;
foreach (const QString &groupName, groups) {
- Nepomuk2::SimpleResource groupRes;
- groupRes.addType(NCO::ContactGroup());
- groupRes.setProperty(NCO::contactGroupName(), groupName);
-
- groupUris << groupRes.uri();
- m_graph << groupRes;
+ groupUris << findGroup(groupName);
}
QUrl contactUri = contact.personContact();
diff --git a/kpeople/nepomuk-feeder/nepomuk-storage.h b/kpeople/nepomuk-feeder/nepomuk-storage.h
index ad5b6bc..a921e22 100644
--- a/kpeople/nepomuk-feeder/nepomuk-storage.h
+++ b/kpeople/nepomuk-feeder/nepomuk-storage.h
@@ -158,6 +158,9 @@ private:
AccountResources findAccount(const QString &path);
void fireGraphTimer();
+
+ QUrl findGroup(const QString& groupName);
+ QHash<QString, QUrl> m_groupCache;
};
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list