allura
リビジョン | 1c05dfadcc8744a02c9f05d8db8e4ff2a5d951ff (tree) |
---|---|
日時 | 2012-05-17 05:24:10 |
作者 | Cory Johns <johnsca@geek...> |
コミッター | Dave Brondsema |
[#4118] Added chunking, intermediate flushing, and filtering to user projects
Signed-off-by: Cory Johns <johnsca@geek.net>
@@ -6,6 +6,7 @@ from pylons import c | ||
6 | 6 | from ming.orm import ThreadLocalORMSession |
7 | 7 | |
8 | 8 | from allura import model as M |
9 | +from allura.lib import utils | |
9 | 10 | from forgewiki import model as WM |
10 | 11 | from forgewiki.wiki_main import ForgeWikiApp |
11 | 12 |
@@ -19,38 +20,40 @@ default_personal_project_tmpl = ("This is the personal project of %s." | ||
19 | 20 | " project such as cloned repositories.\n\n%s") |
20 | 21 | |
21 | 22 | def main(): |
22 | - for p in M.Project.query.find().all(): | |
23 | - user = p.user_project_of | |
24 | - if not user: | |
25 | - continue | |
26 | - | |
27 | - description = p.description | |
28 | - if description is None or re.match(default_description, description): | |
29 | - continue | |
30 | - | |
31 | - app = p.app_instance('wiki') | |
32 | - if app is None: | |
33 | - p.install_app('wiki') | |
34 | - | |
35 | - page = WM.Page.query.get(app_config_id=app.config._id, title='Home') | |
36 | - if page is None: | |
37 | - continue | |
38 | - | |
39 | - c.app = app | |
40 | - c.project = p | |
41 | - c.user = user | |
42 | - | |
43 | - if "This is the personal project of" in page.text: | |
44 | - if description not in page.text: | |
45 | - page.text = "%s\n\n%s" % (page.text, description) | |
23 | + users = M.Neighborhood.query.get(name='Users') | |
24 | + for chunk in utils.chunked_find(M.Project, {'neighborhood_id': users._id}): | |
25 | + for p in chunk: | |
26 | + user = p.user_project_of | |
27 | + if not user: | |
28 | + continue | |
29 | + | |
30 | + description = p.description | |
31 | + if description is None or re.match(default_description, description): | |
32 | + continue | |
33 | + | |
34 | + app = p.app_instance('wiki') | |
35 | + if app is None: | |
36 | + p.install_app('wiki') | |
37 | + | |
38 | + page = WM.Page.query.get(app_config_id=app.config._id, title='Home') | |
39 | + if page is None: | |
40 | + continue | |
41 | + | |
42 | + c.app = app | |
43 | + c.project = p | |
44 | + c.user = user | |
45 | + | |
46 | + if "This is the personal project of" in page.text: | |
47 | + if description not in page.text: | |
48 | + page.text = "%s\n\n%s" % (page.text, description) | |
49 | + log.info("Update wiki home page text for %s" % user.username) | |
50 | + elif "This is the default page" in page.text: | |
51 | + page.text = default_personal_project_tmpl % (user.display_name, description) | |
46 | 52 | log.info("Update wiki home page text for %s" % user.username) |
47 | - elif "This is the default page" in page.text: | |
48 | - page.text = default_personal_project_tmpl % (user.display_name, description) | |
49 | - log.info("Update wiki home page text for %s" % user.username) | |
50 | - else: | |
51 | - pass | |
53 | + else: | |
54 | + pass | |
52 | 55 | |
53 | - ThreadLocalORMSession.flush_all() | |
56 | + ThreadLocalORMSession.flush_all() | |
54 | 57 | |
55 | 58 | if __name__ == '__main__': |
56 | 59 | main() |