• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

allura


Commit MetaInfo

Revision5f1d5e17934804045a8ab0b9f8e8b76ae44b783e (tree)
Time2011-04-01 02:54:06
AuthorRick Copeland <rcopeland@geek...>
CommiterRick Copeland

Log Message

[#1849] Make sure our reindex only tries to load 1024 project records at a time

Signed-off-by: Rick Copeland <rcopeland@geek.net>

Change Summary

Incremental Difference

--- a/Allura/allura/command/show_models.py
+++ b/Allura/allura/command/show_models.py
@@ -7,6 +7,7 @@ from ming.orm import MappedClass, mapper, ThreadLocalORMSession, session, state
77
88 import allura.tasks.index_tasks
99 from allura.lib.exceptions import CompoundError
10+from allura.lib import utils
1011 from . import base
1112
1213 class ShowModelsCommand(base.Command):
@@ -39,37 +40,38 @@ class ReindexCommand(base.Command):
3940 self.basic_setup()
4041 graph = build_model_inheritance_graph()
4142 if self.options.project:
42- projects = [ M.Project.query.get(shortname=self.options.project) ]
43+ q_project = M.Project.query.find(dict(shortname=self.options.project))
4344 elif self.options.neighborhood:
4445 neighborhood_id = M.Neighborhood.query.get(
4546 url_prefix='/%s/' % self.options.neighborhood)._id
46- projects = M.Project.query.find(dict(neighborhood_id=neighborhood_id))
47+ q_project = M.Project.query.find(dict(neighborhood_id=neighborhood_id))
4748 else:
48- projects = M.Project.query.find()
49+ q_project = M.Project.query.find()
4950 seen_dbs = set()
50- for p in projects:
51- if p.database_uri in seen_dbs: continue
52- seen_dbs.add(p.database_uri)
53- base.log.info('Reindex project %s', p.shortname)
54- c.project = p
55- for _, a_cls in dfs(M.Artifact, graph):
56- base.log.info(' %s', a_cls)
57- ref_ids = []
58- for a in a_cls.query.find():
51+ for projects in utils.chunked_iterator(q_project):
52+ for p in projects:
53+ if p.database_uri in seen_dbs: continue
54+ seen_dbs.add(p.database_uri)
55+ base.log.info('Reindex project %s', p.shortname)
56+ c.project = p
57+ for _, a_cls in dfs(M.Artifact, graph):
58+ base.log.info(' %s', a_cls)
59+ ref_ids = []
60+ for a in a_cls.query.find():
61+ try:
62+ M.ArtifactReference.from_artifact(a)
63+ except:
64+ base.log.exception('Making ArtifactReference from %s', a)
65+ continue
66+ ref_ids.append(a.index_id())
67+ M.artifact_orm_session.clear()
5968 try:
60- M.ArtifactReference.from_artifact(a)
61- except:
62- base.log.exception('Making ArtifactReference from %s', a)
63- continue
64- ref_ids.append(a.index_id())
65- M.artifact_orm_session.clear()
66- try:
67- allura.tasks.index_tasks.add_artifacts(ref_ids)
68- except CompoundError, err:
69- base.log.exception('Error indexing artifacts:\n%r', err)
70- base.log.error('%s', err.format_error())
71- M.main_orm_session.flush()
72- M.main_orm_session.clear()
69+ allura.tasks.index_tasks.add_artifacts(ref_ids)
70+ except CompoundError, err:
71+ base.log.exception('Error indexing artifacts:\n%r', err)
72+ base.log.error('%s', err.format_error())
73+ M.main_orm_session.flush()
74+ M.main_orm_session.clear()
7375
7476 class EnsureIndexCommand(base.Command):
7577 min_args=0
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -87,3 +87,15 @@ class StatsHandler(WatchedFileHandler):
8787 if v is not None)
8888 record.exc_info = None # Never put tracebacks in the rtstats log
8989 WatchedFileHandler.emit(self, record)
90+
91+def chunked_iterator(query, pagesize=1024):
92+ page = 0
93+ while True:
94+ results = (
95+ query
96+ .skip(pagesize*page)
97+ .limit(pagesize)
98+ .all())
99+ if not results: break
100+ yield results
101+ page += 1