Switch to unified view

a/scripts/refresh-all-repos.py b/scripts/refresh-all-repos.py
1
import logging
1
import logging
2
import optparse
2
import optparse
3
from collections import defaultdict
4
3
5
from pylons import c
4
from pylons import c
6
from ming.orm import ThreadLocalORMSession
5
from ming.orm import ThreadLocalORMSession
7
6
8
from allura import model as M
7
from allura import model as M
8
from allura.lib import utils
9
9
10
log = logging.getLogger(__name__)
10
log = logging.getLogger(__name__)
11
11
12
PAGESIZE=1024
12
PAGESIZE=1024
13
13
...
...
43
        M.repo.TreeDoc.m.remove({})
43
        M.repo.TreeDoc.m.remove({})
44
        M.repo.TreesDoc.m.remove({})
44
        M.repo.TreesDoc.m.remove({})
45
        M.repo.DiffInfoDoc.m.remove({})
45
        M.repo.DiffInfoDoc.m.remove({})
46
        M.repo.LastCommitDoc.m.remove({})
46
        M.repo.LastCommitDoc.m.remove({})
47
        M.repo.CommitRunDoc.m.remove({})
47
        M.repo.CommitRunDoc.m.remove({})
48
    for chunk in chunked_project_iterator(q_project):
48
    for chunk in utils.chunked_find(M.Project, q_project):
49
        for p in chunk:
49
        for p in chunk:
50
            c.project = p
50
            c.project = p
51
            if projects:
51
            if projects:
52
                mount_points = projects[p.shortname]
52
                mount_points = projects[p.shortname]
53
            else:
53
            else:
...
...
71
                except:
71
                except:
72
                    log.exception('Error refreshing %r', c.app.repo)
72
                    log.exception('Error refreshing %r', c.app.repo)
73
        ThreadLocalORMSession.flush_all()
73
        ThreadLocalORMSession.flush_all()
74
        ThreadLocalORMSession.close_all()
74
        ThreadLocalORMSession.close_all()
75
75
76
def chunked_project_iterator(q_project):
77
    page = 0
78
    while True:
79
        results = (M.Project.query
80
                   .find(q_project)
81
                   .skip(PAGESIZE*page)
82
                   .limit(PAGESIZE)
83
                   .all())
84
        if not results: break
85
        yield results
86
        page += 1
87
88
89
if __name__ == '__main__':
76
if __name__ == '__main__':
90
    main()
77
    main()