Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:12.3
nepomuk-core
do-not-auto-update-the-cache-by-default.diff
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File do-not-auto-update-the-cache-by-default.diff of Package nepomuk-core
commit a398d44788eb4dc17570a61d62a8e22067a2ca77 Author: Vishesh Handa <me@vhanda.in> Date: Sun Feb 3 03:34:40 2013 +0530 Resource: Do not auto update the cache by default The resource class generally connects to the ResourceWatcher, and updates itself whenever any other application changes any data. While, this may be desirable at times, most of the times, it is not required. 1. It creates a massive number of watches which increase the number of messages that are sent across dbus. 2. It slows down the Resource class because its own changes are also propogated back to it. 3. It doesn't really notify anyone that the data has been changed, so the ui code doesn't know when it is supposed to refresh. Added a function setWatchEnabled( bool ), which configures if the Resource should be auto-updated. diff --git a/autotests/test/resourcetests.cpp b/autotests/test/resourcetests.cpp index 4727846..cf4ddc9 100644 --- a/autotests/test/resourcetests.cpp +++ b/autotests/test/resourcetests.cpp @@ -405,6 +405,7 @@ void ResourceTests::tagsUpdate() QVERIFY(tag3.exists()); Resource res(resUri); + res.setWatchEnabled( true ); QList<Tag> tags; tags << tag1 << tag2 << tag3; @@ -487,6 +488,7 @@ void ResourceTests::newResourcesUpdated() QUrl fileUri; Resource fileRes( fileUrl ); + fileRes.setWatchEnabled( true ); QVERIFY(!fileRes.exists()); QVERIFY(fileRes.uri().isEmpty()); @@ -506,6 +508,7 @@ void ResourceTests::newResourcesUpdated() void ResourceTests::identifierUpdate() { Tag tag("Fire"); + tag.setWatchEnabled( true ); QVERIFY(!tag.exists()); // Save the tag @@ -571,6 +574,7 @@ void ResourceTests::resourceDeletion() Tag tag("Poop"); Resource fileRes( fileUrl ); + fileRes.setWatchEnabled(true); fileRes.addTag(tag); const QUrl tagUri = tag.uri(); diff --git a/libnepomukcore/resource/resource.cpp b/libnepomukcore/resource/resource.cpp index 342c0ff..df02be7 100644 --- a/libnepomukcore/resource/resource.cpp +++ b/libnepomukcore/resource/resource.cpp @@ -668,6 +668,22 @@ Nepomuk2::File Nepomuk2::Resource::toFile() const return File( *this ); } +void Nepomuk2::Resource::setWatchEnabled(bool status) +{ + determineFinalResourceData(); + if( m_data ) + return m_data->setWatchEnabled( status ); +} + +bool Nepomuk2::Resource::watchEnabled() +{ + determineFinalResourceData(); + if( m_data ) + return m_data->watchEnabled(); + + return false; +} + // static Nepomuk2::Resource Nepomuk2::Resource::fromResourceUri( const KUrl& uri, const Nepomuk2::Types::Class& type ) diff --git a/libnepomukcore/resource/resource.h b/libnepomukcore/resource/resource.h index 5d99952..114d415 100644 --- a/libnepomukcore/resource/resource.h +++ b/libnepomukcore/resource/resource.h @@ -510,6 +510,18 @@ namespace Nepomuk2 { */ static Resource fromResourceUri( const KUrl& uri, const Nepomuk2::Types::Class& type = Nepomuk2::Types::Class() ); + /** + * Enables automatic updates of the internal cache using a + * ResourceWatcher. + */ + void setWatchEnabled( bool status ); + + /** + * \return \p true if this resource will automatically update its cache + * when the data is changed by some other application + */ + bool watchEnabled(); + private: /** * Determines the final ResourceData and updates m_data if diff --git a/libnepomukcore/resource/resourcedata.cpp b/libnepomukcore/resource/resourcedata.cpp index cb26f97..b4c4bcc 100644 --- a/libnepomukcore/resource/resourcedata.cpp +++ b/libnepomukcore/resource/resourcedata.cpp @@ -69,6 +69,7 @@ Nepomuk2::ResourceData::ResourceData( const QUrl& uri, const QUrl& kickOffUri, c m_modificationMutex(QMutex::Recursive), m_cacheDirty(false), m_addedToWatcher(false), + m_watchEnabled(false), m_rm(rm) { if( !uri.isEmpty() ) { @@ -170,10 +171,7 @@ void Nepomuk2::ResourceData::resetAll( bool isDelete ) if( !m_uri.isEmpty() ) { m_rm->m_initializedData.remove( m_uri ); - if( m_addedToWatcher ) { - m_rm->removeFromWatcher( m_uri ); - m_addedToWatcher = false; - } + removeFromWatcher(); } m_rm->mutex.unlock(); @@ -313,10 +311,21 @@ bool Nepomuk2::ResourceData::store() // Caller must hold m_modificationMutex void Nepomuk2::ResourceData::addToWatcher() { - m_rm->addToWatcher( m_uri ); - m_addedToWatcher = true; + if( m_watchEnabled && !m_addedToWatcher ) { + m_rm->addToWatcher( m_uri ); + m_addedToWatcher = true; + } } +void Nepomuk2::ResourceData::removeFromWatcher() +{ + if( m_addedToWatcher ) { + m_rm->removeFromWatcher( m_uri ); + m_addedToWatcher = false; + } +} + + bool Nepomuk2::ResourceData::load() { QMutexLocker rmlock(&m_rm->mutex); // for updateKickOffLists, but must be locked first @@ -758,3 +767,21 @@ void Nepomuk2::ResourceData::propertyAdded( const Types::Property &prop, const Q m_cache[prop.uri()].append(var); } } + +void Nepomuk2::ResourceData::setWatchEnabled(bool status) +{ + QMutexLocker lock(&m_modificationMutex); + if( m_watchEnabled != status ) { + if( status ) + addToWatcher(); + else + removeFromWatcher(); + + m_watchEnabled = status; + } +} + +bool Nepomuk2::ResourceData::watchEnabled() +{ + return m_watchEnabled; +} diff --git a/libnepomukcore/resource/resourcedata.h b/libnepomukcore/resource/resourcedata.h index 8778af5..2cc36f7 100644 --- a/libnepomukcore/resource/resourcedata.h +++ b/libnepomukcore/resource/resourcedata.h @@ -164,6 +164,8 @@ namespace Nepomuk2 { void propertyRemoved( const Types::Property &prop, const QVariant &value ); void propertyAdded( const Types::Property &prop, const QVariant &value ); + void setWatchEnabled( bool status ); + bool watchEnabled(); private: ResourceData(const ResourceData&); // = delete ResourceData& operator = (const ResourceData&); // = delete @@ -171,6 +173,7 @@ namespace Nepomuk2 { void updateIdentifierLists( const QString& oldIdentifier, const QString& newIdentifier ); void addToWatcher(); + void removeFromWatcher(); /// Will reset this instance to 0 as if constructed without parameters /// Used by remove() and deleteData() @@ -203,6 +206,7 @@ namespace Nepomuk2 { bool m_cacheDirty; bool m_addedToWatcher; + bool m_watchEnabled; ResourceManagerPrivate* m_rm; };
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor