Edgewall Software

Ticket #7723: Cache-metadata-1.patch

File Cache-metadata-1.patch, 1.6 KB (added by cboos, 3 years ago)

retrieve metadata in a helper function and use it also in get_youngest_rev (applies on top of attachment:7723-multirepos-cache-6-r7928.patch)

  • trac/versioncontrol/cache.py

    diff --git a/trac/versioncontrol/cache.py b/trac/versioncontrol/cache.py
    a b  
    9393                        self.reponame, str(cset.rev))) 
    9494        db.commit() 
    9595         
    96     def sync(self, feedback=None): 
    97         db = self.getdb() 
     96    # @cached? => move to RepositoryManager 
     97    def metadata(self, db=None): 
     98        if not db: 
     99            db = self.getdb() 
    98100        cursor = db.cursor() 
    99101        cursor.execute("SELECT name, value FROM repository " 
    100102                       "WHERE id=%%s AND name IN (%s)" %  
     
    103105        metadata = {} 
    104106        for name, value in cursor: 
    105107            metadata[name] = value 
     108        return metadata 
     109 
     110    def sync(self, feedback=None): 
     111        db = self.getdb() 
     112        cursor = db.cursor() 
     113        metadata = self.metadata(db) 
    106114         
    107115        # -- check that we're populating the cache for the correct repository 
    108116        repository_dir = metadata.get(CACHE_REPOSITORY_DIR) 
     
    261269 
    262270    def get_youngest_rev(self): 
    263271        if not hasattr(self, 'youngest'): 
    264             db = self.getdb() 
    265             cursor = db.cursor() 
    266             cursor.execute("SELECT MAX(" + db.cast('rev', 'int') + ") " 
    267                            "FROM revision WHERE repos=%s", (self.reponame,)) 
    268             for rev, in cursor: 
    269                 self.youngest = str(rev) 
     272            metadata = self.metadata() 
     273            self.youngest = metadata.get(CACHE_YOUNGEST_REV) 
    270274        return self.youngest 
    271275 
    272276    def previous_rev(self, rev, path=''):