99
99
self.connection.commit()
100
100
self.connection.close()
102
class ChangeCache (object):
104
def __init__(self, history, cache_path):
105
self.history = history
106
self.log = history.log
108
if not os.path.exists(cache_path):
111
self._changes_filename = os.path.join(cache_path, 'changes.sql')
113
# use a lockfile since the cache folder could be shared across different processes.
114
self._lock = LockFile(os.path.join(cache_path, 'lock'))
117
## # this is fluff; don't slow down startup time with it.
118
## # but it is racy in tests :(
120
## self.log.info('Using change cache %s; %d entries.' % (cache_path, self.size()))
121
## threading.Thread(target=log_sizes).start()
124
return FakeShelf(self._changes_filename)
128
self.log.debug('Closing cache file.')
140
def get_changes(self, revid_list):
142
get a list of changes by their revision_ids. any changes missing
143
from the cache are fetched by calling L{History.get_change_uncached}
144
and inserted into the cache before returning.
148
missing_revid_indices = []
149
cache = self._cache()
150
for revid in revid_list:
151
entry = cache.get(revid)
152
if entry is not None:
155
missing_revids.append(revid)
156
missing_revid_indices.append(len(out))
159
missing_entries = self.history.get_changes_uncached(missing_revids)
160
missing_entry_dict = {}
161
for entry in missing_entries:
162
missing_entry_dict[entry.revid] = entry
163
revid_entry_pairs = []
164
for i, revid in zip(missing_revid_indices, missing_revids):
165
out[i] = entry = missing_entry_dict.get(revid)
166
if entry is not None:
167
revid_entry_pairs.append((revid, entry))
168
cache.add(revid_entry_pairs)
169
return filter(None, out)
173
cache = self._cache()
174
last_revid = util.to_utf8(self.history.last_revid)
175
revision_history = self.history.get_revision_history()
176
return (cache.count() >= len(revision_history)
177
and cache.get(last_revid) is not None)
181
return self._cache().count()
183
def check_rebuild(self, max_time=3600):
185
check if we need to fill in any missing pieces of the cache. pull in
186
any missing changes, but don't work any longer than C{max_time}
189
if self.closed() or self.full():
192
102
self.log.info('Building revision cache...')
193
103
start_time = time.time()
194
104
last_update = time.time()