summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVishesh Handa <me@vhanda.in>2012-08-08 14:08:23 (GMT)
committerVishesh Handa <me@vhanda.in>2012-08-08 15:43:09 (GMT)
commit7bef7c53d3b9a971c203ed4391bf19ac79f381f5 (patch)
tree07d721ec07bd3daaa36a98ab1fed43a817c7be7d
parente4d8cd1f76192dc798f2db09b9e19310d7c1d65f (diff)
ResourceWatcher: add *count() methods for resources, properties and types
These count methods are faster than returning the full list and then counting the number of items in the list. This also fixes an infinite loop where a temporary Resource is created when querying for the number of resources being watched. The temporary Resource is deleted, which results in ResourceData::resetAll being callled which again called ResourceWatcher::resources(), and the cycle countinues. BUG: 304796 REVIEW: 105927
-rw-r--r--libnepomukcore/datamanagement/resourcewatcher.cpp16
-rw-r--r--libnepomukcore/datamanagement/resourcewatcher.h27
-rw-r--r--libnepomukcore/resource/resourcedata.cpp2
3 files changed, 44 insertions, 1 deletions
diff --git a/libnepomukcore/datamanagement/resourcewatcher.cpp b/libnepomukcore/datamanagement/resourcewatcher.cpp
index c7fc425..c7d3359 100644
--- a/libnepomukcore/datamanagement/resourcewatcher.cpp
+++ b/libnepomukcore/datamanagement/resourcewatcher.cpp
@@ -221,6 +221,22 @@ QList< Nepomuk2::Types::Class > Nepomuk2::ResourceWatcher::types() const
return types;
}
+int Nepomuk2::ResourceWatcher::propertyCount() const
+{
+ return d->m_properties.size();
+}
+
+int Nepomuk2::ResourceWatcher::resourceCount() const
+{
+ return d->m_resources.size();
+}
+
+int Nepomuk2::ResourceWatcher::typeCount() const
+{
+ return d->m_types.size();
+}
+
+
void Nepomuk2::ResourceWatcher::setProperties(const QList< Nepomuk2::Types::Property >& properties_)
{
d->m_properties.clear();
diff --git a/libnepomukcore/datamanagement/resourcewatcher.h b/libnepomukcore/datamanagement/resourcewatcher.h
index af20945..14a5b83 100644
--- a/libnepomukcore/datamanagement/resourcewatcher.h
+++ b/libnepomukcore/datamanagement/resourcewatcher.h
@@ -192,6 +192,15 @@ namespace Nepomuk2 {
QList<Types::Class> types() const;
/**
+ * \brief Return the number of types that are being watched
+ *
+ * This method is slightly faster than called types().count()
+ *
+ * \sa types addType setType
+ */
+ int typeCount() const;
+
+ /**
* \brief The resources that have been configured via addResource() and setResources().
*
* Every change to one of these resources will be
@@ -200,6 +209,15 @@ namespace Nepomuk2 {
QList<Nepomuk2::Resource> resources() const;
/**
+ * \brief Return the number of resources that are being watched
+ *
+ * This method is slightly faster than called resources().count()
+ *
+ * \sa resources addResource setResources
+ */
+ int resourceCount() const;
+
+ /**
* \brief The properties that have been configured via addProperty() and setProperties().
*
* Every change to a value of any of these properties
@@ -208,6 +226,15 @@ namespace Nepomuk2 {
QList<Types::Property> properties() const;
/**
+ * \brief Return the number of properties that are being watched
+ *
+ * This method is slightly faster than called properties().count()
+ *
+ * \sa properties addProperty setProperty
+ */
+ int propertyCount() const;
+
+ /**
* \brief Start the signalling of changes.
*
* Before calling this method no signal will be emitted. In
diff --git a/libnepomukcore/resource/resourcedata.cpp b/libnepomukcore/resource/resourcedata.cpp
index f3590f3..b18ffaa 100644
--- a/libnepomukcore/resource/resourcedata.cpp
+++ b/libnepomukcore/resource/resourcedata.cpp
@@ -171,7 +171,7 @@ void Nepomuk2::ResourceData::resetAll( bool isDelete )
// See load() for an explanation of the QMetaObject call
// stop the watcher since we do not want to watch all changes in case there is no ResourceData left
- if(m_rm->m_watcher->resources().count() == 1) {
+ if(m_rm->m_watcher->resourceCount() == 1) {
QMetaObject::invokeMethod(m_rm->m_watcher, "stop", Qt::AutoConnection);
}