Changeset 1358 for pykota

Show
Ignore:
Timestamp:
02/23/04 23:53:21 (21 years ago)
Author:
jalet
Message:

Don't retrieve data when it's not needed, to avoid database queries

Location:
pykota/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/NEWS

    r1356 r1358  
    2222PyKota NEWS : 
    2323 
     24    - 1.18alpha8 : 
     25     
     26        - Don't retrieve data when not needed. 
     27          This avoids many database queries. 
     28         
    2429    - 1.18alpha7 : 
    2530     
  • pykota/trunk/pykota/storage.py

    r1333 r1358  
    2222# 
    2323# $Log$ 
     24# Revision 1.42  2004/02/23 22:53:21  jalet 
     25# Don't retrieve data when it's not needed, to avoid database queries 
     26# 
    2427# Revision 1.41  2004/02/04 17:12:33  jalet 
    2528# Removing a printer from a printers group should work now. 
     
    257260        self.PricePerPage = None 
    258261        self.PricePerJob = None 
    259         self.LastJob = None 
    260          
     262         
     263    def __getattr__(self, name) :     
     264        """Delays data retrieval until it's really needed.""" 
     265        if name == "LastJob" :  
     266            self.LastJob = self.parent.getPrinterLastJob(self) 
     267            return self.LastJob 
     268        else : 
     269            raise AttributeError, name 
     270             
    261271    def addJobToHistory(self, jobid, user, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None) : 
    262272        """Adds a job to the printer's history.""" 
     
    309319        self.HardLimit = None 
    310320        self.DateLimit = None 
    311         self.ParentPrintersUserPQuota = (user.Exists and printer.Exists and parent.getParentPrintersUserPQuota(self)) or [] 
     321         
     322    def __getattr__(self, name) :     
     323        """Delays data retrieval until it's really needed.""" 
     324        if name == "ParentPrintersUserPQuota" :  
     325            self.ParentPrintersUserPQuota = (self.User.Exists and self.Printer.Exists and self.parent.getParentPrintersUserPQuota(self)) or [] 
     326            return self.ParentPrintersUserPQuota 
     327        else : 
     328            raise AttributeError, name 
    312329         
    313330    def setDateLimit(self, datelimit) :     
     
    383400    def __init__(self, parent) : 
    384401        StorageObject.__init__(self, parent) 
    385         self.User = None 
    386         self.Printer = None 
     402        self.UserName = None 
     403        self.PrinterName = None 
    387404        self.JobId = None 
    388405        self.PrinterPageCounter = None 
     
    396413        self.JobOptions = None 
    397414         
     415    def __getattr__(self, name) :     
     416        """Delays data retrieval until it's really needed.""" 
     417        if name == "User" :  
     418            self.User = self.parent.getUser(self.UserName) 
     419            return self.User 
     420        elif name == "Printer" :     
     421            self.Printer = self.parent.getPrinter(self.PrinterName) 
     422            return self.Printer 
     423        else : 
     424            raise AttributeError, name 
     425         
    398426class StorageLastJob(StorageJob) : 
    399427    """Printer's Last Job class.""" 
     
    401429        StorageJob.__init__(self, parent) 
    402430        self.Printer = printer 
     431        self.UserName = None 
     432         
     433    def __getattr__(self, name) :     
     434        """Delays data retrieval until it's really needed.""" 
     435        if name == "User" :  
     436            self.User = self.parent.getUser(self.UserName) 
     437            return self.User 
     438        else :     
     439            raise AttributeError, name 
    403440         
    404441    def setSize(self, jobsize) : 
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1357 r1358  
    2222# 
    2323# $Log$ 
     24# Revision 1.55  2004/02/23 22:53:21  jalet 
     25# Don't retrieve data when it's not needed, to avoid database queries 
     26# 
    2427# Revision 1.54  2004/02/20 16:38:39  jalet 
    2528# ldapcache directive marked as experimental 
     
    472475            printer.PricePerJob = float(fields.get("pykotaPricePerJob")[0] or 0.0) 
    473476            printer.PricePerPage = float(fields.get("pykotaPricePerPage")[0] or 0.0) 
    474             printer.LastJob = self.getPrinterLastJob(printer) 
    475477            printer.uniqueMember = fields.get("uniqueMember", []) 
    476478            printer.Exists = 1 
     
    557559                lastjob.ident = result[0][0] 
    558560                lastjob.JobId = fields.get("pykotaJobId")[0] 
    559                 lastjob.User = self.getUser(fields.get("pykotaUserName")[0]) 
     561                lastjob.UserName = fields.get("pykotaUserName")[0] 
    560562                lastjob.PrinterPageCounter = int(fields.get("pykotaPrinterPageCounter")[0] or 0) 
    561563                lastjob.JobSize = int(fields.get("pykotaJobSize", [0])[0]) 
     
    636638                printer.PricePerPage = float(fields.get("pykotaPricePerPage")[0] or 0.0) 
    637639                printer.uniqueMember = fields.get("uniqueMember", []) 
    638                 printer.LastJob = self.getPrinterLastJob(printer) 
    639640                printer.Exists = 1 
    640641                printers.append(printer) 
     
    993994                job.JobDate = "%04i-%02i-%02i %02i:%02i:%02i" % (year, month, day, hour, minute, second) 
    994995                if (datelimit is None) or (job.JobDate <= datelimit) : 
    995                     job.User = self.getUser(fields.get("pykotaUserName")[0]) 
    996                     job.Printer = self.getPrinter(fields.get("pykotaPrinterName")[0]) 
     996                    job.UserName = fields.get("pykotaUserName")[0] 
     997                    job.PrinterName = fields.get("pykotaPrinterName")[0] 
    997998                    job.Exists = 1 
    998999                    jobs.append(job) 
  • pykota/trunk/pykota/storages/sql.py

    r1332 r1358  
    2222# 
    2323# $Log$ 
     24# Revision 1.37  2004/02/23 22:53:21  jalet 
     25# Don't retrieve data when it's not needed, to avoid database queries 
     26# 
    2427# Revision 1.36  2004/02/04 13:24:41  jalet 
    2528# pkprinters can now remove printers from printers groups. 
     
    9295            printer.PricePerJob = fields.get("priceperjob") 
    9396            printer.PricePerPage = fields.get("priceperpage") 
    94             printer.LastJob = self.getPrinterLastJob(printer) 
    9597            printer.Exists = 1 
    9698        return printer     
     
    139141            lastjob.ident = fields.get("id") 
    140142            lastjob.JobId = fields.get("jobid") 
    141             lastjob.User = self.getUser(fields.get("username")) 
     143            lastjob.UserName = fields.get("username") 
    142144            lastjob.PrinterPageCounter = fields.get("pagecounter") 
    143145            lastjob.JobSize = fields.get("jobsize") 
     
    204206                    printer.PricePerJob = record.get("priceperjob") 
    205207                    printer.PricePerPage = record.get("priceperpage") 
    206                     printer.LastJob = self.getPrinterLastJob(printer) 
    207208                    printer.Exists = 1 
    208209                    printers.append(printer) 
     
    391392                job.JobOptions = fields.get("options") 
    392393                job.JobDate = fields.get("jobdate") 
    393                 job.User = self.getUser(fields.get("username")) 
    394                 job.Printer = self.getPrinter(fields.get("printername")) 
     394                job.UserName = fields.get("username") 
     395                job.PrinterName = fields.get("printername") 
    395396                job.Exists = 1 
    396397                jobs.append(job) 
  • pykota/trunk/pykota/version.py

    r1356 r1358  
    2222# 
    2323 
    24 __version__ = "1.18alpha7_unofficial" 
     24__version__ = "1.18alpha8_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""