From f2f1d5b1da4f985bcbb0c075cf42efcacecae2a6 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 3 Jul 2009 17:23:37 +0200 Subject: =?UTF-8?q?Timestamps=20f=C3=BCr=20Benutzercache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/UserBackendMysql/UserBackendMysql.cpp | 81 ++++++++++++++++++++--- src/modules/UserBackendMysql/UserBackendMysql.h | 22 +++--- 2 files changed, 84 insertions(+), 19 deletions(-) (limited to 'src/modules') diff --git a/src/modules/UserBackendMysql/UserBackendMysql.cpp b/src/modules/UserBackendMysql/UserBackendMysql.cpp index 6d64a51..82258e8 100644 --- a/src/modules/UserBackendMysql/UserBackendMysql.cpp +++ b/src/modules/UserBackendMysql/UserBackendMysql.cpp @@ -134,11 +134,18 @@ void UserBackendMysql::configFinished() { } -boost::shared_ptr > UserBackendMysql::getUserList() throw(Core::Exception) { +boost::shared_ptr > UserBackendMysql::getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception) { application->getThreadManager()->detach(); boost::unique_lock lock(mutex); + if(timestamp) { + if(timestamp->is_not_a_date_time() || *timestamp < lastUpdate) + *timestamp = lastUpdate; + else + return boost::shared_ptr >(); + } + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); @@ -164,11 +171,18 @@ boost::shared_ptr > UserBackendM return users; } -boost::shared_ptr UserBackendMysql::getUserInfo(unsigned long uid) throw(Core::Exception) { +boost::shared_ptr UserBackendMysql::getUserInfo(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception) { application->getThreadManager()->detach(); boost::unique_lock lock(mutex); + if(timestamp) { + if(timestamp->is_not_a_date_time() || *timestamp < lastUpdate) + *timestamp = lastUpdate; + else + return boost::shared_ptr(); + } + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); @@ -205,11 +219,18 @@ boost::shared_ptr UserBackendMysql::getUserInfo(unsigned throw Core::Exception(Core::Exception::NOT_FOUND); } -boost::shared_ptr UserBackendMysql::getUserInfoByName(const std::string &name) throw(Core::Exception) { +boost::shared_ptr UserBackendMysql::getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { application->getThreadManager()->detach(); boost::unique_lock lock(mutex); + if(timestamp) { + if(timestamp->is_not_a_date_time() || *timestamp < lastUpdate) + *timestamp = lastUpdate; + else + return boost::shared_ptr(); + } + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); @@ -243,11 +264,18 @@ boost::shared_ptr UserBackendMysql::getUserInfoByName(co throw Core::Exception(Core::Exception::NOT_FOUND); } -boost::shared_ptr > UserBackendMysql::getUserGroupList(unsigned long uid) throw(Core::Exception) { +boost::shared_ptr > UserBackendMysql::getUserGroupList(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception) { application->getThreadManager()->detach(); boost::unique_lock lock(mutex); + if(timestamp) { + if(timestamp->is_not_a_date_time() || *timestamp < lastUpdate) + *timestamp = lastUpdate; + else + return boost::shared_ptr >(); + } + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); @@ -275,11 +303,18 @@ boost::shared_ptr > UserBackendMysql::getUserGroup } -boost::shared_ptr > UserBackendMysql::getGroupList() throw(Core::Exception) { +boost::shared_ptr > UserBackendMysql::getGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception) { application->getThreadManager()->detach(); boost::unique_lock lock(mutex); + if(timestamp) { + if(timestamp->is_not_a_date_time() || *timestamp < lastUpdate) + *timestamp = lastUpdate; + else + return boost::shared_ptr >(); + } + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); @@ -302,11 +337,18 @@ boost::shared_ptr > UserBackend return groups; } -boost::shared_ptr UserBackendMysql::getGroupInfo(unsigned long gid) throw(Core::Exception) { +boost::shared_ptr UserBackendMysql::getGroupInfo(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception) { application->getThreadManager()->detach(); boost::unique_lock lock(mutex); + if(timestamp) { + if(timestamp->is_not_a_date_time() || *timestamp < lastUpdate) + *timestamp = lastUpdate; + else + return boost::shared_ptr(); + } + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); @@ -335,11 +377,18 @@ boost::shared_ptr UserBackendMysql::getGroupInfo(unsign throw Core::Exception(Core::Exception::NOT_FOUND); } -boost::shared_ptr UserBackendMysql::getGroupInfoByName(const std::string &name) throw(Core::Exception) { +boost::shared_ptr UserBackendMysql::getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception) { application->getThreadManager()->detach(); boost::unique_lock lock(mutex); + if(timestamp) { + if(timestamp->is_not_a_date_time() || *timestamp < lastUpdate) + *timestamp = lastUpdate; + else + return boost::shared_ptr(); + } + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); @@ -365,11 +414,18 @@ boost::shared_ptr UserBackendMysql::getGroupInfoByName( throw Core::Exception(Core::Exception::NOT_FOUND); } -boost::shared_ptr > UserBackendMysql::getGroupUserList(unsigned long gid) throw(Core::Exception) { +boost::shared_ptr > UserBackendMysql::getGroupUserList(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception) { application->getThreadManager()->detach(); boost::unique_lock lock(mutex); + if(timestamp) { + if(timestamp->is_not_a_date_time() || *timestamp < lastUpdate) + *timestamp = lastUpdate; + else + return boost::shared_ptr >(); + } + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); @@ -396,11 +452,18 @@ boost::shared_ptr > UserBackendMysql::getGroupUser return users; } -boost::shared_ptr > UserBackendMysql::getFullUserGroupList() throw(Core::Exception) { +boost::shared_ptr > UserBackendMysql::getFullUserGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception) { application->getThreadManager()->detach(); boost::unique_lock lock(mutex); + if(timestamp) { + if(timestamp->is_not_a_date_time() || *timestamp < lastUpdate) + *timestamp = lastUpdate; + else + return boost::shared_ptr >(); + } + if(!mysql || mysql_ping(mysql)) throw Core::Exception(Core::Exception::NOT_AVAILABLE); diff --git a/src/modules/UserBackendMysql/UserBackendMysql.h b/src/modules/UserBackendMysql/UserBackendMysql.h index eadbf3b..52a134a 100644 --- a/src/modules/UserBackendMysql/UserBackendMysql.h +++ b/src/modules/UserBackendMysql/UserBackendMysql.h @@ -49,26 +49,28 @@ class UserBackendMysql : public Common::UserBackend, private Core::Configurable MYSQL *mysql; + boost::posix_time::ptime lastUpdate; + boost::mutex mutex; protected: virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool); virtual void configFinished(); - virtual boost::shared_ptr > getUserList() throw(Core::Exception); - virtual boost::shared_ptr getUserInfo(unsigned long uid) throw(Core::Exception); - virtual boost::shared_ptr getUserInfoByName(const std::string &name) throw(Core::Exception); - virtual boost::shared_ptr > getUserGroupList(unsigned long uid) throw(Core::Exception); + virtual boost::shared_ptr > getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr getUserInfo(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr getUserInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr > getUserGroupList(unsigned long uid, boost::posix_time::ptime *timestamp) throw(Core::Exception); - virtual boost::shared_ptr > getGroupList() throw(Core::Exception); - virtual boost::shared_ptr getGroupInfo(unsigned long gid) throw(Core::Exception); - virtual boost::shared_ptr getGroupInfoByName(const std::string &name) throw(Core::Exception); - virtual boost::shared_ptr > getGroupUserList(unsigned long gid) throw(Core::Exception); + virtual boost::shared_ptr > getGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr getGroupInfo(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr getGroupInfoByName(const std::string &name, boost::posix_time::ptime *timestamp) throw(Core::Exception); + virtual boost::shared_ptr > getGroupUserList(unsigned long gid, boost::posix_time::ptime *timestamp) throw(Core::Exception); - virtual boost::shared_ptr > getFullUserGroupList() throw(Core::Exception); + virtual boost::shared_ptr > getFullUserGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception); public: - UserBackendMysql(Common::Application *application0) : application(application0), port(0), mysql(0) { + UserBackendMysql(Common::Application *application0) : application(application0), port(0), mysql(0), lastUpdate(boost::posix_time::microsec_clock::universal_time()) { application->getConfigManager()->registerConfigurable(this); } -- cgit v1.2.3