Changeset 170 in tracdarcs


Ignore:
Timestamp:
05/08/10 17:14:29 (21 months ago)
Author:
lele@…
Hash name:
20100508151429-97f81-d8e79c8c9d05a79fd74262ee17eda4f47a2164a5
Message:

Keep a per file per revision cache of darcs annotate

Location:
tracdarcs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tracdarcs/components.py

    r161 r170  
    108108            c.execute('SELECT repo_id,node_id,rev,content,size ' 
    109109                      'FROM darcs_cache LIMIT 1') 
     110            c.execute('SELECT repo_id,node_id,rev ' 
     111                      'FROM darcs_annotate_cache LIMIT 1') 
    110112            return False 
    111113        except: 
     
    129131        drop_table('darcs_node_changes') 
    130132        drop_table('darcs_cache') 
     133        drop_table('darcs_annotate_cache') 
    131134 
    132135        connector = DatabaseManager(self.env)._get_connector()[0] 
     
    161164            Column('content',type=blobtype), 
    162165            Column('size',type='int')] 
     166        ann_cache_table = Table('darcs_annotate_cache', key=('repo_id','node_id','rev','up_to_line'))[ 
     167            Column('repo_id',type='int'), 
     168            Column('node_id',type='int'), 
     169            Column('rev',type='int'), 
     170            Column('up_to_line',type='int'), 
     171            Column('blame_rev',type='int')] 
    163172        c = db.cursor() 
    164         for t in [rev_table,node_table,change_table,cache_table]: 
     173        for t in [rev_table,node_table,change_table,cache_table,ann_cache_table]: 
    165174            for stmt in connector.to_sql(t): 
    166175                c.execute(stmt) 
  • tracdarcs/repository.py

    r168 r170  
    372372        """Provide detailed backward history for the content of this Node. 
    373373 
    374         Retrieve an array of revisions parsing `darcs annotate`. 
     374        Retrieve an array of revisions parsing `darcs annotate`. Since 
     375        that is (still) not fast enough for some repository, we write 
     376        a cache of the information: a future annotate on the same file 
     377        at the same revision won't reexecute `darcs annotate`. 
    375378        """ 
    376379 
     
    380383 
    381384        c = self.repos.db.cursor() 
     385 
     386        # Since darcs is faster and faster in building the content 
     387        # of a file for more and more recent changes, compute the 
     388        # optimal revision to build the cache of 
     389        crev = self._get_cached_rev() 
     390        if crev is None: 
     391            crev = self.rev 
     392 
     393        # Check if the annotate cache is already present 
     394        c.execute('SELECT up_to_line,blame_rev FROM darcs_annotate_cache ' 
     395                  'WHERE repo_id = %s AND node_id = %s AND rev = %s ' 
     396                  'ORDER BY up_to_line', (self.repos.id, self.__node_id, crev)) 
     397        row = c.fetchone() 
     398        if row is not None: 
     399            self.__log.debug('Annotate cache hit for %s at rev %s', self.path, crev) 
     400            revs = [] 
     401            line = 0 
     402            # Expand the cache, producing a list of revisions, one per line 
     403            while row is not None: 
     404                while line<row[0]: 
     405                    revs.append(row[1]) 
     406                    line += 1 
     407                row = c.fetchone() 
     408            return revs 
     409 
     410        # No cache, build it 
    382411 
    383412        class DarcsXMLAnnotateHandler(ContentHandler): 
     
    424453        parser.close() 
    425454 
    426         return handler.revisions 
     455        revs = handler.revisions 
     456 
     457        # Write a compressed representation 
     458 
     459        self.__log.debug('Writing annotate cache for %s at rev %s', self.path, crev) 
     460        prev = None 
     461        for i,rev in enumerate(revs): 
     462            if prev is not None: 
     463                if prev != rev: 
     464                    c.execute('INSERT INTO darcs_annotate_cache (repo_id,node_id,rev,up_to_line,blame_rev) ' 
     465                              'VALUES (%s,%s,%s,%s,%s)', 
     466                              (self.repos.id, self.__node_id, crev, i, prev)) 
     467                    prev = rev 
     468                    lastline = i 
     469            else: 
     470                prev = rev 
     471                lastline = 0 
     472        if lastline != len(revs): 
     473            c.execute('INSERT INTO darcs_annotate_cache (repo_id,node_id,rev,up_to_line,blame_rev) ' 
     474                      'VALUES (%s,%s,%s,%s,%s)', 
     475                      (self.repos.id, self.__node_id, crev, len(revs), revs[-1])) 
     476 
     477        return revs 
    427478 
    428479    def get_properties(self): 
Note: See TracChangeset for help on using the changeset viewer.