Show
Ignore:
Timestamp:
02/09/06 00:15:46 (18 years ago)
Author:
jerome
Message:

Huge speed improvements when using the --delete command line option for pkprinters, pkbcodes and edpykota.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storages/sql.py

    r2654 r2657  
    203203            fields = result[0] 
    204204            user.ident = fields.get("id") 
    205             user.Name = self.databaseToUserCharset(fields.get("username", username)) 
    206205            user.LimitBy = fields.get("limitby") or "quota" 
    207206            user.AccountBalance = fields.get("balance") 
    208207            user.LifeTimePaid = fields.get("lifetimepaid") 
    209208            user.Email = fields.get("email") 
     209            user.Description = self.databaseToUserCharset(fields.get("description")) 
    210210            user.OverCharge = fields.get("overcharge", 1.0) 
    211211            user.Exists = 1 
     
    220220            fields = result[0] 
    221221            group.ident = fields.get("id") 
    222             group.Name = self.databaseToUserCharset(fields.get("groupname", groupname)) 
    223222            group.LimitBy = fields.get("limitby") or "quota" 
    224223            group.AccountBalance = fields.get("balance") 
    225224            group.LifeTimePaid = fields.get("lifetimepaid") 
     225            group.Description = self.databaseToUserCharset(fields.get("description")) 
    226226            group.Exists = 1 
    227227        return group 
     
    235235            fields = result[0] 
    236236            printer.ident = fields.get("id") 
    237             printer.Name = self.databaseToUserCharset(fields.get("printername", printername)) 
    238237            printer.PricePerJob = fields.get("priceperjob") or 0.0 
    239238            printer.PricePerPage = fields.get("priceperpage") or 0.0 
     
    255254            fields = result[0] 
    256255            code.ident = fields.get("id") 
    257             code.BillingCode = self.databaseToUserCharset(fields.get("billingcode")) 
    258256            code.Description = self.databaseToUserCharset(fields.get("description") or "") 
    259257            code.Balance = fields.get("balance") or 0.0 
     
    375373        result = self.doSearch("SELECT * FROM printers") 
    376374        if result : 
     375            patterns = printerpattern.split(",") 
    377376            for record in result : 
    378377                pname = self.databaseToUserCharset(record["printername"]) 
    379                 if self.tool.matchString(pname, printerpattern.split(",")) : 
     378                if self.tool.matchString(pname, patterns) : 
    380379                    printer = StoragePrinter(self, pname) 
    381380                    printer.ident = record.get("id") 
     
    394393        return printers         
    395394         
     395    def getMatchingUsers(self, userpattern) : 
     396        """Returns the list of all users for which name matches a certain pattern.""" 
     397        users = [] 
     398        # We 'could' do a SELECT username FROM users WHERE username LIKE ... 
     399        # but we don't because other storages semantics may be different, so every 
     400        # storage should use fnmatch to match patterns and be storage agnostic 
     401        result = self.doSearch("SELECT * FROM users") 
     402        if result : 
     403            patterns = userpattern.split(",") 
     404            for record in result : 
     405                uname = self.databaseToUserCharset(record["username"]) 
     406                if self.tool.matchString(uname, patterns) : 
     407                    user = StorageUser(self, uname) 
     408                    user.ident = record.get("id") 
     409                    user.LimitBy = record.get("limitby") or "quota" 
     410                    user.AccountBalance = record.get("balance") 
     411                    user.LifeTimePaid = record.get("lifetimepaid") 
     412                    user.Email = record.get("email") 
     413                    user.Description = self.databaseToUserCharset(record.get("description")) 
     414                    user.OverCharge = record.get("overcharge", 1.0) 
     415                    user.Exists = 1 
     416                    users.append(user) 
     417                    self.cacheEntry("USERS", user.Name, user) 
     418        return users         
     419         
     420    def getMatchingGroups(self, grouppattern) : 
     421        """Returns the list of all groups for which name matches a certain pattern.""" 
     422        groups = [] 
     423        # We 'could' do a SELECT groupname FROM groups WHERE groupname LIKE ... 
     424        # but we don't because other storages semantics may be different, so every 
     425        # storage should use fnmatch to match patterns and be storage agnostic 
     426        result = self.doSearch("SELECT groups.*,COALESCE(SUM(balance), 0.0) AS balance, COALESCE(SUM(lifetimepaid), 0.0) AS lifetimepaid FROM groups LEFT OUTER JOIN users ON users.id IN (SELECT userid FROM groupsmembers WHERE groupid=groups.id) GROUP BY groups.id,groups.groupname,groups.limitby,groups.description") 
     427        if result : 
     428            patterns = grouppattern.split(",") 
     429            for record in result : 
     430                gname = self.databaseToUserCharset(record["groupname"]) 
     431                if self.tool.matchString(gname, patterns) : 
     432                    group = StorageGroup(self, gname) 
     433                    group.ident = record.get("id") 
     434                    group.LimitBy = record.get("limitby") or "quota" 
     435                    group.AccountBalance = record.get("balance") 
     436                    group.LifeTimePaid = record.get("lifetimepaid") 
     437                    group.Description = self.databaseToUserCharset(record.get("description")) 
     438                    group.Exists = 1 
     439                    groups.append(group) 
     440                    self.cacheEntry("GROUPS", group.Name, group) 
     441        return groups         
     442         
    396443    def getMatchingBillingCodes(self, billingcodepattern) : 
    397444        """Returns the list of all billing codes for which the label matches a certain pattern.""" 
     
    399446        result = self.doSearch("SELECT * FROM billingcodes") 
    400447        if result : 
     448            patterns = billingcodepattern.split(",") 
    401449            for record in result : 
    402450                bcode = self.databaseToUserCharset(record["billingcode"]) 
    403                 if self.tool.matchString(bcode, billingcodepattern.split(",")) : 
     451                if self.tool.matchString(bcode, patterns) : 
    404452                    code = StorageBillingCode(self, bcode) 
    405453                    code.ident = record.get("id")