Changeset 185 in tracdarcs for tracdarcs/repository.py


Ignore:
Timestamp:
06/11/10 16:05:16 (2 years ago)
Author:
lele@…
Hash name:
20100611140516-97f81-7eff9b8bd5140541eff4858d96bcf7b194974480
Message:

Implement eager cache
A new option, eager_annotations, controls whether the cache is
computed lazily as before, that is on demand at the first request, or
when the changeset is added (at sync time).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tracdarcs/repository.py

    r184 r185  
    6161 
    6262class DarcsRepository(Repository): 
    63     def __init__(self, db, path, log, darcscmd, possible_encodings, params): 
     63    def __init__(self, db, path, log, darcscmd, possible_encodings, 
     64                 params, eager_annotations): 
    6465        if IS_TRAC_0_12_OR_BETTER: 
    6566            Repository.__init__(self, 'darcs:%s' % path, params, log) 
     
    7273            self.log = log 
    7374            self.id = get_repository_id(db, path) or 0 
     75        self.eager_annotations = eager_annotations 
    7476        if IS_TRAC_0_10_X: 
    7577            self.sync() 
     
    233235 
    234236    def sync(self, rev_callback=None, clean=False): 
     237        from dbutil import format_elapsed_time as trepr 
     238 
    235239        # Import any new changesets, if any 
    236         update_darcsdb(self.db, self.__cmd, self.log, self.id, 
    237                        rev_callback=rev_callback, clean=clean) 
     240 
     241        newrevs = update_darcsdb(self.db, self.__cmd, self.log, self.id, 
     242                                 rev_callback=rev_callback, clean=clean) 
     243 
     244        # In eager mode, precompute the content and the annotations for 
     245        # each file modified or added by latest changesets 
     246 
     247        if self.eager_annotations and newrevs: 
     248            i = 1 
     249            count = len(newrevs) 
     250            for rev in newrevs: 
     251                t0 = time.time() 
     252 
     253                c = self.get_changeset(rev) 
     254                for path,kind,change,prev_path,prev_rev in c.get_changes(): 
     255                    if kind==Node.FILE and (change==Changeset.EDIT or change==Changeset.ADD): 
     256                        node = self.get_node(path, rev) 
     257                        node.get_content() 
     258                        node.get_annotations() 
     259 
     260                t1 = time.time() 
     261                usec = (t1-t0) * 1e6 
     262                self.log.info('Preannotated changeset %d/%d: %s', i, count, trepr(usec)) 
     263                i += 1 
    238264 
    239265class DarcsNode(Node): 
Note: See TracChangeset for help on using the changeset viewer.