Changeset 1137
- Timestamp:
- 10/06/03 15:12:28 (21 years ago)
- Location:
- pykota/trunk/pykota
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storage.py
r1132 r1137 21 21 # 22 22 # $Log$ 23 # Revision 1.22 2003/10/06 13:12:27 jalet 24 # More work on caching 25 # 23 26 # Revision 1.21 2003/10/03 09:02:20 jalet 24 27 # Logs cache store actions too … … 385 388 return lastjob 386 389 390 def getGroupMembers(self, group) : 391 """Returns the group's members list from in-group cache.""" 392 if self.usecache : 393 if not hasattr(group, "Members") : 394 self.tool.logdebug("Cache miss (%s->Members)" % group.Name) 395 group.Members = self.getGroupMembersFromBackend(group) 396 self.tool.logdebug("Cache store (%s->Members)" % group.Name) 397 else : 398 self.tool.logdebug("Cache hit (%s->Members)" % group.Name) 399 else : 400 group.Members = self.getGroupMembersFromBackend(group) 401 return group.Members 402 403 def getUserGroups(self, user) : 404 """Returns the user's groups list from in-user cache.""" 405 if self.usecache : 406 if not hasattr(user, "Groups") : 407 self.tool.logdebug("Cache miss (%s->Groups)" % user.Name) 408 user.Groups = self.getUserGroupsFromBackend(user) 409 self.tool.logdebug("Cache store (%s->Groups)" % user.Name) 410 else : 411 self.tool.logdebug("Cache hit (%s->Groups)" % user.Name) 412 else : 413 user.Groups = self.getUserGroupsFromBackend(user) 414 return user.Groups 415 387 416 def openConnection(pykotatool) : 388 417 """Returns a connection handle to the appropriate Quota Storage Database.""" -
pykota/trunk/pykota/storages/ldapstorage.py
r1133 r1137 21 21 # 22 22 # $Log$ 23 # Revision 1.29 2003/10/06 13:12:28 jalet 24 # More work on caching 25 # 23 26 # Revision 1.28 2003/10/03 12:27:02 jalet 24 27 # Several optimizations, especially with LDAP backend … … 266 269 group.AccountBalance = 0.0 267 270 group.LifeTimePaid = 0.0 268 group.Members = self.getGroupMembers(group) 269 for member in group.Members : 271 for member in self.getGroupMembers(group) : 270 272 if member.Exists : 271 273 group.AccountBalance += member.AccountBalance … … 346 348 grouppquota.PageCounter = 0 347 349 grouppquota.LifePageCounter = 0 348 if (not hasattr(group, "Members")) or (group.Members is None) :349 group.Members = self.getGroupMembers(group)350 350 usernamesfilter = "".join(["(pykotaUserName=%s)" % member.Name for member in group.Members]) 351 351 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)(|%s))" % (printer.Name, usernamesfilter), ["pykotaPageCounter", "pykotaLifePageCounter"], base=self.info["userquotabase"]) … … 384 384 return lastjob 385 385 386 def getUserGroups(self, user) : 386 def getGroupMembersFromBackend(self, group) : 387 """Returns the group's members list.""" 388 groupmembers = [] 389 result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(%s=%s)))" % (group.Name, self.info["grouprdn"], group.Name), [self.info["groupmembers"]], base=self.info["groupbase"]) 390 if result : 391 for username in result[0][1].get(self.info["groupmembers"], []) : 392 groupmembers.append(self.getUser(username)) 393 return groupmembers 394 395 def getUserGroupsFromBackend(self, user) : 387 396 """Returns the user's groups list.""" 388 397 groups = [] … … 392 401 groups.append(self.getGroup(fields.get(self.info["grouprdn"])[0])) 393 402 return groups 394 395 def getGroupMembers(self, group) :396 """Returns the group's members list."""397 groupmembers = []398 result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(%s=%s)))" % (group.Name, self.info["grouprdn"], group.Name), [self.info["groupmembers"]], base=self.info["groupbase"])399 if result :400 for username in result[0][1].get(self.info["groupmembers"], []) :401 groupmembers.append(self.getUser(username))402 return groupmembers403 403 404 404 def getMatchingPrinters(self, printerpattern) : -
pykota/trunk/pykota/storages/pgstorage.py
r1136 r1137 21 21 # 22 22 # $Log$ 23 # Revision 1.17 2003/10/06 13:12:28 jalet 24 # More work on caching 25 # 23 26 # Revision 1.16 2003/10/03 18:01:49 jalet 24 27 # Nothing interesting... … … 256 259 return lastjob 257 260 258 def getUserGroups(self, user) : 259 """Returns the user's groups list.""" 260 groups = [] 261 result = self.doSearch("SELECT groupname FROM groupsmembers JOIN groups ON groupsmembers.groupid=groups.id WHERE userid=%s" % self.doQuote(user.ident)) 262 if result : 263 for record in result : 264 groups.append(self.getGroup(record.get("groupname"))) 265 return groups 266 267 def getGroupMembers(self, group) : 261 def getGroupMembersFromBackend(self, group) : 268 262 """Returns the group's members list.""" 269 263 groupmembers = [] … … 281 275 self.cacheEntry("USERS", user.Name, user) 282 276 return groupmembers 277 278 def getUserGroupsFromBackend(self, user) : 279 """Returns the user's groups list.""" 280 groups = [] 281 result = self.doSearch("SELECT groupname FROM groupsmembers JOIN groups ON groupsmembers.groupid=groups.id WHERE userid=%s" % self.doQuote(user.ident)) 282 if result : 283 for record in result : 284 groups.append(self.getGroup(record.get("groupname"))) 285 return groups 283 286 284 287 def getMatchingPrinters(self, printerpattern) :