Show More
@@ -42,7 +42,8 b' sys.path.append(project_path)' | |||||
42 | from rhodecode.config.conf import INDEX_EXTENSIONS |
|
42 | from rhodecode.config.conf import INDEX_EXTENSIONS | |
43 | from rhodecode.model.scm import ScmModel |
|
43 | from rhodecode.model.scm import ScmModel | |
44 | from rhodecode.lib.utils2 import safe_unicode |
|
44 | from rhodecode.lib.utils2 import safe_unicode | |
45 |
from rhodecode.lib.indexers import SCHEMA, IDX_NAME, CHGSETS_SCHEMA, |
|
45 | from rhodecode.lib.indexers import SCHEMA, IDX_NAME, CHGSETS_SCHEMA, \ | |
|
46 | CHGSET_IDX_NAME | |||
46 |
|
47 | |||
47 | from rhodecode.lib.vcs.exceptions import ChangesetError, RepositoryError, \ |
|
48 | from rhodecode.lib.vcs.exceptions import ChangesetError, RepositoryError, \ | |
48 | NodeDoesNotExistError |
|
49 | NodeDoesNotExistError | |
@@ -114,11 +115,11 b' class WhooshIndexingDaemon(object):' | |||||
114 | index_paths_ = set() |
|
115 | index_paths_ = set() | |
115 | try: |
|
116 | try: | |
116 | tip = repo.get_changeset('tip') |
|
117 | tip = repo.get_changeset('tip') | |
117 | for topnode, dirs, files in tip.walk('/'): |
|
118 | for _topnode, _dirs, files in tip.walk('/'): | |
118 | for f in files: |
|
119 | for f in files: | |
119 | index_paths_.add(jn(repo.path, f.path)) |
|
120 | index_paths_.add(jn(repo.path, f.path)) | |
120 |
|
121 | |||
121 |
except RepositoryError |
|
122 | except RepositoryError: | |
122 | log.debug(traceback.format_exc()) |
|
123 | log.debug(traceback.format_exc()) | |
123 | pass |
|
124 | pass | |
124 | return index_paths_ |
|
125 | return index_paths_ | |
@@ -186,10 +187,12 b' class WhooshIndexingDaemon(object):' | |||||
186 | if start_rev is None: |
|
187 | if start_rev is None: | |
187 | start_rev = repo[0].raw_id |
|
188 | start_rev = repo[0].raw_id | |
188 |
|
189 | |||
189 |
log.debug('indexing changesets in %s starting at rev: %s' % |
|
190 | log.debug('indexing changesets in %s starting at rev: %s' % | |
|
191 | (repo_name, start_rev)) | |||
190 |
|
192 | |||
191 | indexed=0 |
|
193 | indexed = 0 | |
192 | for cs in repo.get_changesets(start=start_rev): |
|
194 | for cs in repo.get_changesets(start=start_rev): | |
|
195 | log.debug(' >> %s' % cs) | |||
193 | writer.add_document( |
|
196 | writer.add_document( | |
194 | raw_id=unicode(cs.raw_id), |
|
197 | raw_id=unicode(cs.raw_id), | |
195 | owner=unicode(repo.contact), |
|
198 | owner=unicode(repo.contact), | |
@@ -205,8 +208,16 b' class WhooshIndexingDaemon(object):' | |||||
205 | indexed += 1 |
|
208 | indexed += 1 | |
206 |
|
209 | |||
207 | log.debug('indexed %d changesets for repo %s' % (indexed, repo_name)) |
|
210 | log.debug('indexed %d changesets for repo %s' % (indexed, repo_name)) | |
|
211 | return indexed | |||
208 |
|
212 | |||
209 | def index_files(self, file_idx_writer, repo_name, repo): |
|
213 | def index_files(self, file_idx_writer, repo_name, repo): | |
|
214 | """ | |||
|
215 | Index files for given repo_name | |||
|
216 | ||||
|
217 | :param file_idx_writer: the whoosh index writer to add to | |||
|
218 | :param repo_name: name of the repository we're indexing | |||
|
219 | :param repo: instance of vcs repo | |||
|
220 | """ | |||
210 | i_cnt = iwc_cnt = 0 |
|
221 | i_cnt = iwc_cnt = 0 | |
211 | log.debug('building index for [%s]' % repo.path) |
|
222 | log.debug('building index for [%s]' % repo.path) | |
212 | for idx_path in self.get_paths(repo): |
|
223 | for idx_path in self.get_paths(repo): | |
@@ -214,7 +225,9 b' class WhooshIndexingDaemon(object):' | |||||
214 | i_cnt += i |
|
225 | i_cnt += i | |
215 | iwc_cnt += iwc |
|
226 | iwc_cnt += iwc | |
216 |
|
227 | |||
217 |
log.debug('added %s files %s with content for repo %s' % |
|
228 | log.debug('added %s files %s with content for repo %s' % | |
|
229 | (i_cnt + iwc_cnt, iwc_cnt, repo.path)) | |||
|
230 | return i_cnt, iwc_cnt | |||
218 |
|
231 | |||
219 | def update_changeset_index(self): |
|
232 | def update_changeset_index(self): | |
220 | idx = open_dir(self.index_location, indexname=CHGSET_IDX_NAME) |
|
233 | idx = open_dir(self.index_location, indexname=CHGSET_IDX_NAME) | |
@@ -223,6 +236,7 b' class WhooshIndexingDaemon(object):' | |||||
223 | writer = idx.writer() |
|
236 | writer = idx.writer() | |
224 | writer_is_dirty = False |
|
237 | writer_is_dirty = False | |
225 | try: |
|
238 | try: | |
|
239 | indexed_total = 0 | |||
226 | for repo_name, repo in self.repo_paths.items(): |
|
240 | for repo_name, repo in self.repo_paths.items(): | |
227 | # skip indexing if there aren't any revs in the repo |
|
241 | # skip indexing if there aren't any revs in the repo | |
228 | num_of_revs = len(repo) |
|
242 | num_of_revs = len(repo) | |
@@ -246,16 +260,20 b' class WhooshIndexingDaemon(object):' | |||||
246 |
|
260 | |||
247 | # there are new changesets to index or a new repo to index |
|
261 | # there are new changesets to index or a new repo to index | |
248 | if last_rev == 0 or num_of_revs > last_rev + 1: |
|
262 | if last_rev == 0 or num_of_revs > last_rev + 1: | |
249 |
# delete the docs in the index for the previous |
|
263 | # delete the docs in the index for the previous | |
|
264 | # last changeset(s) | |||
250 | for hit in results: |
|
265 | for hit in results: | |
251 |
q = qp.parse(u"last:t AND %s AND raw_id:%s" % |
|
266 | q = qp.parse(u"last:t AND %s AND raw_id:%s" % | |
252 | (repo_name, hit['raw_id'])) |
|
267 | (repo_name, hit['raw_id'])) | |
253 | writer.delete_by_query(q) |
|
268 | writer.delete_by_query(q) | |
254 |
|
269 | |||
255 | # index from the previous last changeset + all new ones |
|
270 | # index from the previous last changeset + all new ones | |
256 |
self.index_changesets(writer, |
|
271 | indexed_total += self.index_changesets(writer, | |
|
272 | repo_name, repo, start_id) | |||
257 | writer_is_dirty = True |
|
273 | writer_is_dirty = True | |
258 |
|
274 | log.debug('indexed %s changesets for repo %s' % ( | ||
|
275 | indexed_total, repo_name) | |||
|
276 | ) | |||
259 | finally: |
|
277 | finally: | |
260 | if writer_is_dirty: |
|
278 | if writer_is_dirty: | |
261 | log.debug('>> COMMITING CHANGES TO CHANGESET INDEX<<') |
|
279 | log.debug('>> COMMITING CHANGES TO CHANGESET INDEX<<') | |
@@ -263,6 +281,7 b' class WhooshIndexingDaemon(object):' | |||||
263 | log.debug('>> COMMITTED CHANGES TO CHANGESET INDEX<<') |
|
281 | log.debug('>> COMMITTED CHANGES TO CHANGESET INDEX<<') | |
264 | else: |
|
282 | else: | |
265 | writer.cancel |
|
283 | writer.cancel | |
|
284 | log.debug('>> NOTHING TO COMMIT<<') | |||
266 |
|
285 | |||
267 | def update_file_index(self): |
|
286 | def update_file_index(self): | |
268 | log.debug((u'STARTING INCREMENTAL INDEXING UPDATE FOR EXTENSIONS %s ' |
|
287 | log.debug((u'STARTING INCREMENTAL INDEXING UPDATE FOR EXTENSIONS %s ' | |
@@ -296,10 +315,11 b' class WhooshIndexingDaemon(object):' | |||||
296 | indexed_time = fields['modtime'] |
|
315 | indexed_time = fields['modtime'] | |
297 | mtime = self.get_node_mtime(node) |
|
316 | mtime = self.get_node_mtime(node) | |
298 | if mtime > indexed_time: |
|
317 | if mtime > indexed_time: | |
299 |
# The file has changed, delete it and add it to |
|
318 | # The file has changed, delete it and add it to | |
300 | # files to reindex |
|
319 | # the list of files to reindex | |
301 |
log.debug( |
|
320 | log.debug( | |
302 | indexed_path, mtime, indexed_time) |
|
321 | 'adding to reindex list %s mtime: %s vs %s' % ( | |
|
322 | indexed_path, mtime, indexed_time) | |||
303 | ) |
|
323 | ) | |
304 | writer.delete_by_term('fileid', indexed_path) |
|
324 | writer.delete_by_term('fileid', indexed_path) | |
305 | writer_is_dirty = True |
|
325 | writer_is_dirty = True | |
@@ -347,6 +367,7 b' class WhooshIndexingDaemon(object):' | |||||
347 | writer.commit(merge=True) |
|
367 | writer.commit(merge=True) | |
348 | log.debug('>>> FINISHED REBUILDING INDEX <<<') |
|
368 | log.debug('>>> FINISHED REBUILDING INDEX <<<') | |
349 | else: |
|
369 | else: | |
|
370 | log.debug('>> NOTHING TO COMMIT<<') | |||
350 | writer.cancel() |
|
371 | writer.cancel() | |
351 |
|
372 | |||
352 | def build_indexes(self): |
|
373 | def build_indexes(self): | |
@@ -357,7 +378,8 b' class WhooshIndexingDaemon(object):' | |||||
357 | if not os.path.exists(self.index_location): |
|
378 | if not os.path.exists(self.index_location): | |
358 | os.mkdir(self.index_location) |
|
379 | os.mkdir(self.index_location) | |
359 |
|
380 | |||
360 |
chgset_idx = create_in(self.index_location, CHGSETS_SCHEMA, |
|
381 | chgset_idx = create_in(self.index_location, CHGSETS_SCHEMA, | |
|
382 | indexname=CHGSET_IDX_NAME) | |||
361 | chgset_idx_writer = chgset_idx.writer() |
|
383 | chgset_idx_writer = chgset_idx.writer() | |
362 |
|
384 | |||
363 | file_idx = create_in(self.index_location, SCHEMA, indexname=IDX_NAME) |
|
385 | file_idx = create_in(self.index_location, SCHEMA, indexname=IDX_NAME) |
General Comments 0
You need to be logged in to leave comments.
Login now