|
a/Allura/allura/model/repo_refresh.py |
|
b/Allura/allura/model/repo_refresh.py |
1 |
import logging
|
1 |
import logging
|
2 |
from itertools import chain
|
2 |
from itertools import chain
|
3 |
from cPickle import dumps
|
3 |
from cPickle import dumps
|
4 |
|
4 |
|
5 |
import bson
|
5 |
import bson
|
6 |
from tg import config
|
|
|
7 |
|
6 |
|
8 |
from ming.base import Object
|
7 |
from ming.base import Object
|
9 |
|
8 |
|
10 |
from allura.lib import utils
|
9 |
from allura.lib import utils
|
11 |
from allura.model.repo import CommitDoc, TreeDoc, TreesDoc, DiffInfoDoc
|
10 |
from allura.model.repo import CommitDoc, TreeDoc, TreesDoc, DiffInfoDoc
|
|
... |
|
... |
61 |
if (i+1) % 100 == 0:
|
60 |
if (i+1) % 100 == 0:
|
62 |
log.info('Compute diffs %d: %s', (i+1), ci._id)
|
61 |
log.info('Compute diffs %d: %s', (i+1), ci._id)
|
63 |
|
62 |
|
64 |
# Send notifications
|
63 |
# Send notifications
|
65 |
if notify:
|
64 |
if notify:
|
66 |
send_notifications(commit_ids)
|
65 |
send_notifications(repo, commit_ids)
|
67 |
|
66 |
|
68 |
def refresh_commit_trees(ci, cache):
|
67 |
def refresh_commit_trees(ci, cache):
|
69 |
'''Refresh the list of trees included withn a commit'''
|
68 |
'''Refresh the list of trees included withn a commit'''
|
70 |
trees_doc = TreesDoc(dict(
|
69 |
trees_doc = TreesDoc(dict(
|
71 |
_id=ci._id,
|
70 |
_id=ci._id,
|
|
... |
|
... |
219 |
|
218 |
|
220 |
def unknown_commit_ids(all_commit_ids):
|
219 |
def unknown_commit_ids(all_commit_ids):
|
221 |
'''filter out all commit ids that have already been cached'''
|
220 |
'''filter out all commit ids that have already been cached'''
|
222 |
result = []
|
221 |
result = []
|
223 |
for chunk in utils.chunked_iter(all_commit_ids, QSIZE):
|
222 |
for chunk in utils.chunked_iter(all_commit_ids, QSIZE):
|
|
|
223 |
chunk = list(chunk)
|
224 |
q = CommitDoc.m.find(_id={'$in':chunk})
|
224 |
q = CommitDoc.m.find(dict(_id={'$in':chunk}))
|
225 |
known_commit_ids = set(ci._id for ci in q)
|
225 |
known_commit_ids = set(ci._id for ci in q)
|
226 |
result += [ oid for oid in chunk if oid not in known_commit_ids ]
|
226 |
result += [ oid for oid in chunk if oid not in known_commit_ids ]
|
227 |
return result
|
227 |
return result
|
228 |
|
228 |
|
229 |
def compute_diffs(repo_id, tree_cache, rhs_ci):
|
229 |
def compute_diffs(repo_id, tree_cache, rhs_ci):
|
|
... |
|
... |
278 |
return tree_cache
|
278 |
return tree_cache
|
279 |
|
279 |
|
280 |
def send_notifications(repo, commit_ids):
|
280 |
def send_notifications(repo, commit_ids):
|
281 |
'''Create appropriate notification and feed objects for a refresh'''
|
281 |
'''Create appropriate notification and feed objects for a refresh'''
|
282 |
from allura.model import Feed, Notification
|
282 |
from allura.model import Feed, Notification
|
|
|
283 |
from allura.model.repository import config
|
283 |
commit_msgs = []
|
284 |
commit_msgs = []
|
284 |
for oids in utils.chunked_iter(commit_ids, QSIZE):
|
285 |
for oids in utils.chunked_iter(commit_ids, QSIZE):
|
285 |
chunk = list(oids)
|
286 |
chunk = list(oids)
|
286 |
index = dict(
|
287 |
index = dict(
|
287 |
(doc._id, doc)
|
288 |
(doc._id, doc)
|
288 |
for doc in CommitDoc.m.find(dict(_id={'$in':chunk})))
|
289 |
for doc in Commit.query.find(dict(_id={'$in':chunk})))
|
289 |
for oid in chunk:
|
290 |
for oid in chunk:
|
290 |
ci = index[oid]
|
291 |
ci = index[oid]
|
291 |
href = '%s%sci/%s/' % (
|
292 |
href = '%s%sci/%s/' % (
|
292 |
config.common_prefix,
|
293 |
config.common_prefix,
|
293 |
repo.url(),
|
294 |
repo.url(),
|