summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-07-14 19:24:06 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-07-14 19:24:06 +0200
commit5c18630e1c81ac5267c9356e27c1a8f81b4ef6f7 (patch)
tree70dd9ce1d3491abf0a9a44d77b5613f6d62271c4
parent3bc9888fcf5efe373a14be12382e1b8a882e348e (diff)
downloadmad-5c18630e1c81ac5267c9356e27c1a8f81b4ef6f7.tar
mad-5c18630e1c81ac5267c9356e27c1a8f81b4ef6f7.zip
Benutze gecachete Benutzerlisten, wenn der Server nicht verfügbar ist
-rw-r--r--src/Common/UserCache.cpp36
1 files changed, 27 insertions, 9 deletions
diff --git a/src/Common/UserCache.cpp b/src/Common/UserCache.cpp
index b0dd37a..4058c4c 100644
--- a/src/Common/UserCache.cpp
+++ b/src/Common/UserCache.cpp
@@ -26,12 +26,15 @@ namespace Common {
boost::shared_ptr<const std::map<unsigned long, UserInfo> > UserCache::getUserList(boost::posix_time::ptime *timestamp) throw(Core::Exception) {
boost::lock_guard<boost::recursive_mutex> lock(mutex);
+ boost::posix_time::ptime newTime(userTime);
+
try {
- boost::shared_ptr<const std::map<unsigned long, UserInfo> > newUsers = backend->getUserList(&userTime);
+ boost::shared_ptr<const std::map<unsigned long, UserInfo> > newUsers = backend->getUserList(&newTime);
if(newUsers) {
users = newUsers;
userException = Core::Exception();
+ userTime = newTime;
userNames.reset(new std::map<std::string, unsigned long>);
for(std::map<unsigned long, UserInfo>::const_iterator user = users->begin(); user != users->end(); ++user)
@@ -45,8 +48,11 @@ boost::shared_ptr<const std::map<unsigned long, UserInfo> > UserCache::getUserLi
}
}
catch(Core::Exception e) {
- users.reset();
- userException = e;
+ if(e.getErrorCode() != Core::Exception::NOT_AVAILABLE || !users) {
+ users.reset();
+ userException = e;
+ userTime = newTime;
+ }
}
if((!timestamp) || timestamp->is_not_a_date_time() || (*timestamp < userTime)) {
@@ -111,12 +117,15 @@ boost::shared_ptr<const std::set<unsigned long> > UserCache::getUserGroupList(un
boost::shared_ptr<const std::map<unsigned long, GroupInfo> > UserCache::getGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception) {
boost::lock_guard<boost::recursive_mutex> lock(mutex);
+ boost::posix_time::ptime newTime(groupTime);
+
try {
- boost::shared_ptr<const std::map<unsigned long, GroupInfo> > newGroups = backend->getGroupList(&groupTime);
+ boost::shared_ptr<const std::map<unsigned long, GroupInfo> > newGroups = backend->getGroupList(&newTime);
if(newGroups) {
groups = newGroups;
groupException = Core::Exception();
+ groupTime = newTime;
groupNames.reset(new std::map<std::string, unsigned long>);
for(std::map<unsigned long, GroupInfo>::const_iterator group = groups->begin(); group != groups->end(); ++group)
@@ -130,8 +139,11 @@ boost::shared_ptr<const std::map<unsigned long, GroupInfo> > UserCache::getGroup
}
}
catch(Core::Exception e) {
- groups.reset();
- groupException = e;
+ if(e.getErrorCode() != Core::Exception::NOT_AVAILABLE || !groups) {
+ groups.reset();
+ groupException = e;
+ groupTime = newTime;
+ }
}
if((!timestamp) || timestamp->is_not_a_date_time() || (*timestamp < groupTime)) {
@@ -195,12 +207,15 @@ boost::shared_ptr<const std::set<unsigned long> > UserCache::getGroupUserList(un
boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > UserCache::getFullUserGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception) {
boost::lock_guard<boost::recursive_mutex> lock(mutex);
+ boost::posix_time::ptime newTime(userGroupTime);
+
try {
- boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > newUserGroups = backend->getFullUserGroupList(&userGroupTime);
+ boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > newUserGroups = backend->getFullUserGroupList(&newTime);
if(newUserGroups) {
userGroups = newUserGroups;
userGroupException = Core::Exception();
+ userGroupTime = newTime;
groupUsers.reset(new std::multimap<unsigned long, unsigned long>);
for(std::multimap<unsigned long, unsigned long>::const_iterator usergroup = userGroups->begin(); usergroup != userGroups->end(); ++usergroup)
@@ -214,8 +229,11 @@ boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > UserCache:
}
}
catch(Core::Exception e) {
- userGroups.reset();
- userGroupException = e;
+ if(e.getErrorCode() != Core::Exception::NOT_AVAILABLE || !userGroups) {
+ userGroups.reset();
+ userGroupException = e;
+ userGroupTime = newTime;
+ }
}
if((!timestamp) || timestamp->is_not_a_date_time() || (*timestamp < userTime)) {