Changeset 1137

Show
Ignore:
Timestamp:
10/06/03 15:12:28 (21 years ago)
Author:
jalet
Message:

More work on caching

Location:
pykota/trunk/pykota
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storage.py

    r1132 r1137  
    2121# 
    2222# $Log$ 
     23# Revision 1.22  2003/10/06 13:12:27  jalet 
     24# More work on caching 
     25# 
    2326# Revision 1.21  2003/10/03 09:02:20  jalet 
    2427# Logs cache store actions too 
     
    385388        return lastjob     
    386389         
     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         
    387416def openConnection(pykotatool) : 
    388417    """Returns a connection handle to the appropriate Quota Storage Database.""" 
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1133 r1137  
    2121# 
    2222# $Log$ 
     23# Revision 1.29  2003/10/06 13:12:28  jalet 
     24# More work on caching 
     25# 
    2326# Revision 1.28  2003/10/03 12:27:02  jalet 
    2427# Several optimizations, especially with LDAP backend 
     
    266269            group.AccountBalance = 0.0 
    267270            group.LifeTimePaid = 0.0 
    268             group.Members = self.getGroupMembers(group) 
    269             for member in group.Members : 
     271            for member in self.getGroupMembers(group) : 
    270272                if member.Exists : 
    271273                    group.AccountBalance += member.AccountBalance 
     
    346348                grouppquota.PageCounter = 0 
    347349                grouppquota.LifePageCounter = 0 
    348                 if (not hasattr(group, "Members")) or (group.Members is None) : 
    349                     group.Members = self.getGroupMembers(group) 
    350350                usernamesfilter = "".join(["(pykotaUserName=%s)" % member.Name for member in group.Members]) 
    351351                result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)(|%s))" % (printer.Name, usernamesfilter), ["pykotaPageCounter", "pykotaLifePageCounter"], base=self.info["userquotabase"]) 
     
    384384        return lastjob 
    385385         
    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) :         
    387396        """Returns the user's groups list.""" 
    388397        groups = [] 
     
    392401                groups.append(self.getGroup(fields.get(self.info["grouprdn"])[0])) 
    393402        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 groupmembers         
    403403         
    404404    def getMatchingPrinters(self, printerpattern) : 
  • pykota/trunk/pykota/storages/pgstorage.py

    r1136 r1137  
    2121# 
    2222# $Log$ 
     23# Revision 1.17  2003/10/06 13:12:28  jalet 
     24# More work on caching 
     25# 
    2326# Revision 1.16  2003/10/03 18:01:49  jalet 
    2427# Nothing interesting... 
     
    256259        return lastjob 
    257260             
    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) :         
    268262        """Returns the group's members list.""" 
    269263        groupmembers = [] 
     
    281275                self.cacheEntry("USERS", user.Name, user) 
    282276        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         
    283286         
    284287    def getMatchingPrinters(self, printerpattern) :