Changeset 1133

Show
Ignore:
Timestamp:
10/03/03 14:27:03 (21 years ago)
Author:
jalet
Message:

Several optimizations, especially with LDAP backend

Location:
pykota/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/edpykota

    r1120 r1133  
    2323# 
    2424# $Log$ 
     25# Revision 1.58  2003/10/03 12:27:01  jalet 
     26# Several optimizations, especially with LDAP backend 
     27# 
    2528# Revision 1.57  2003/08/20 16:01:19  jalet 
    2629# Comment added. 
     
    473476                    allentries.append((entry, entrypquota)) 
    474477            else :    
    475                 allentries = getattr(self.storage, "getPrinter%ssAndQuotas" % suffix)(printer) 
     478                allentries = getattr(self.storage, "getPrinter%ssAndQuotas" % suffix)(printer, names) 
    476479                 
    477             for (entry, entrypquota) in [(e, q) for (e, q) in allentries if self.matchString(e.Name, names)] : 
     480            for (entry, entrypquota) in allentries : 
    478481                if not changed.has_key(entry.Name) : 
    479482                    changed[entry.Name] = {} 
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1131 r1133  
    2121# 
    2222# $Log$ 
     23# Revision 1.28  2003/10/03 12:27:02  jalet 
     24# Several optimizations, especially with LDAP backend 
     25# 
    2326# Revision 1.27  2003/10/03 08:57:55  jalet 
    2427# Caching mechanism now caches all that's cacheable. 
     
    403406        printers = [] 
    404407        # see comment at the same place in pgstorage.py 
    405         result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName", "pykotaPricePerPage", "pykotaPricePerJob"], base=self.info["printerbase"]) 
     408        result = self.doSearch("(&(objectClass=pykotaPrinter)(|%s))" % "".join(["(pykotaPrinterName=%s)" % pname for pname in printerpattern.split(",")]), ["pykotaPrinterName", "pykotaPricePerPage", "pykotaPricePerJob"], base=self.info["printerbase"]) 
    406409        if result : 
    407410            for (printerid, fields) in result : 
    408411                printername = fields["pykotaPrinterName"][0] 
    409                 if self.tool.matchString(printername, [ printerpattern ]) : 
    410                     printer = StoragePrinter(self, printername) 
    411                     printer.ident = printerid 
    412                     printer.PricePerJob = float(fields.get("pykotaPricePerJob")[0] or 0.0) 
    413                     printer.PricePerPage = float(fields.get("pykotaPricePerPage")[0] or 0.0) 
    414                     printer.LastJob = self.getPrinterLastJob(printer) 
    415                     printer.Exists = 1 
    416                     printers.append(printer) 
    417                     self.cacheEntry("PRINTERS", printer.Name, printer) 
     412                printer = StoragePrinter(self, printername) 
     413                printer.ident = printerid 
     414                printer.PricePerJob = float(fields.get("pykotaPricePerJob")[0] or 0.0) 
     415                printer.PricePerPage = float(fields.get("pykotaPricePerPage")[0] or 0.0) 
     416                printer.LastJob = self.getPrinterLastJob(printer) 
     417                printer.Exists = 1 
     418                printers.append(printer) 
     419                self.cacheEntry("PRINTERS", printer.Name, printer) 
    418420        return printers         
    419421         
    420     def getPrinterUsersAndQuotas(self, printer, names=None) :         
     422    def getPrinterUsersAndQuotas(self, printer, names=["*"]) :         
    421423        """Returns the list of users who uses a given printer, along with their quotas.""" 
    422424        usersandquotas = [] 
    423         result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s))" % printer.Name, ["pykotaUserName", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=self.info["userquotabase"]) 
     425        result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)(|%s))" % (printer.Name, "".join(["(pykotaUserName=%s)" % uname for uname in names])), ["pykotaUserName", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=self.info["userquotabase"]) 
    424426        if result : 
    425427            for (userquotaid, fields) in result : 
    426                 user = self.getUser(fields["pykotaUserName"][0]) 
    427                 if (names is None) or self.tool.matchString(user.Name, names) : 
    428                     userpquota = StorageUserPQuota(self, user, printer) 
    429                     userpquota.ident = userquotaid 
    430                     userpquota.PageCounter = int(fields.get("pykotaPageCounter")[0] or 0) 
    431                     userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter")[0] or 0) 
    432                     userpquota.SoftLimit = fields.get("pykotaSoftLimit") 
    433                     if userpquota.SoftLimit is not None : 
    434                         if userpquota.SoftLimit[0].upper() == "NONE" : 
    435                             userpquota.SoftLimit = None 
    436                         else :     
    437                             userpquota.SoftLimit = int(userpquota.SoftLimit[0]) 
    438                     userpquota.HardLimit = fields.get("pykotaHardLimit") 
    439                     if userpquota.HardLimit is not None : 
    440                         if userpquota.HardLimit[0].upper() == "NONE" : 
    441                             userpquota.HardLimit = None 
    442                         elif userpquota.HardLimit is not None :     
    443                             userpquota.HardLimit = int(userpquota.HardLimit[0]) 
    444                     userpquota.DateLimit = fields.get("pykotaDateLimit") 
    445                     if userpquota.DateLimit is not None : 
    446                         if userpquota.DateLimit[0].upper() == "NONE" :  
    447                             userpquota.DateLimit = None 
    448                         else :     
    449                             userpquota.DateLimit = userpquota.DateLimit[0] 
    450                     userpquota.Exists = 1 
    451                     usersandquotas.append((user, userpquota)) 
    452                     self.cacheEntry("USERPQUOTAS", "%s@%s" % (user.Name, printer.Name), userpquota) 
     428                user = self.getUser(fields.get("pykotaUserName")[0]) 
     429                userpquota = StorageUserPQuota(self, user, printer) 
     430                userpquota.ident = userquotaid 
     431                userpquota.PageCounter = int(fields.get("pykotaPageCounter")[0] or 0) 
     432                userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter")[0] or 0) 
     433                userpquota.SoftLimit = fields.get("pykotaSoftLimit") 
     434                if userpquota.SoftLimit is not None : 
     435                    if userpquota.SoftLimit[0].upper() == "NONE" : 
     436                        userpquota.SoftLimit = None 
     437                    else :     
     438                        userpquota.SoftLimit = int(userpquota.SoftLimit[0]) 
     439                userpquota.HardLimit = fields.get("pykotaHardLimit") 
     440                if userpquota.HardLimit is not None : 
     441                    if userpquota.HardLimit[0].upper() == "NONE" : 
     442                        userpquota.HardLimit = None 
     443                    elif userpquota.HardLimit is not None :     
     444                        userpquota.HardLimit = int(userpquota.HardLimit[0]) 
     445                userpquota.DateLimit = fields.get("pykotaDateLimit") 
     446                if userpquota.DateLimit is not None : 
     447                    if userpquota.DateLimit[0].upper() == "NONE" :  
     448                        userpquota.DateLimit = None 
     449                    else :     
     450                        userpquota.DateLimit = userpquota.DateLimit[0] 
     451                userpquota.Exists = 1 
     452                usersandquotas.append((user, userpquota)) 
     453                self.cacheEntry("USERPQUOTAS", "%s@%s" % (user.Name, printer.Name), userpquota) 
    453454        usersandquotas.sort(lambda x, y : cmp(x[0].Name, y[0].Name))             
    454455        return usersandquotas 
    455456                 
    456     def getPrinterGroupsAndQuotas(self, printer, names=None) :         
     457    def getPrinterGroupsAndQuotas(self, printer, names=["*"]) :         
    457458        """Returns the list of groups which uses a given printer, along with their quotas.""" 
    458459        groupsandquotas = [] 
    459         result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s))" % printer.Name, ["pykotaGroupName"], base=self.info["groupquotabase"]) 
     460        result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s)(|%s))" % (printer.Name, "".join(["(pykotaGroupName=%s)" % gname for gname in names])), ["pykotaGroupName"], base=self.info["groupquotabase"]) 
    460461        if result : 
    461462            for (groupquotaid, fields) in result : 
    462463                group = self.getGroup(fields.get("pykotaGroupName")[0]) 
    463                 if (names is None) or self.tool.matchString(group.Name, names) : 
    464                     grouppquota = self.getGroupPQuota(group, printer) 
    465                     groupsandquotas.append((group, grouppquota)) 
     464                grouppquota = self.getGroupPQuota(group, printer) 
     465                groupsandquotas.append((group, grouppquota)) 
    466466        groupsandquotas.sort(lambda x, y : cmp(x[0].Name, y[0].Name))             
    467467        return groupsandquotas 
  • pykota/trunk/pykota/storages/pgstorage.py

    r1131 r1133  
    2121# 
    2222# $Log$ 
     23# Revision 1.15  2003/10/03 12:27:03  jalet 
     24# Several optimizations, especially with LDAP backend 
     25# 
    2326# Revision 1.14  2003/10/03 08:57:55  jalet 
    2427# Caching mechanism now caches all that's cacheable. 
     
    302305        if result : 
    303306            for record in result : 
    304                 user = StorageUser(self, record.get("username")) 
    305                 if (names is None) or self.tool.matchString(user.Name, names) : 
     307                if (names is None) or self.tool.matchString(record.get("username"), names) : 
     308                    user = StorageUser(self, record.get("username")) 
    306309                    user.ident = record.get("uid") 
    307310                    user.LimitBy = record.get("limitby") 
     
    329332        if result : 
    330333            for record in result : 
    331                 group = self.getGroup(record.get("groupname")) 
    332                 if (names is None) or self.tool.matchString(group.Name, names) : 
     334                if (names is None) or self.tool.matchString(record.get("groupname"), names) : 
     335                    group = self.getGroup(record.get("groupname")) 
    333336                    grouppquota = self.getGroupPQuota(group, printer) 
    334337                    groupsandquotas.append((group, grouppquota))