|
a/Allura/allura/tasks/index_tasks.py |
|
b/Allura/allura/tasks/index_tasks.py |
|
... |
|
... |
13 |
def add_artifacts(ref_ids, update_solr=True, update_refs=True):
|
13 |
def add_artifacts(ref_ids, update_solr=True, update_refs=True):
|
14 |
'''Add the referenced artifacts to SOLR and shortlinks'''
|
14 |
'''Add the referenced artifacts to SOLR and shortlinks'''
|
15 |
from allura import model as M
|
15 |
from allura import model as M
|
16 |
from allura.lib.search import find_shortlinks, solarize
|
16 |
from allura.lib.search import find_shortlinks, solarize
|
17 |
exceptions = []
|
17 |
exceptions = []
|
|
|
18 |
solr_updates = []
|
18 |
with _indexing_disabled(M.session.artifact_orm_session._get()):
|
19 |
with _indexing_disabled(M.session.artifact_orm_session._get()):
|
19 |
for ref_id in ref_ids:
|
20 |
for ref in M.ArtifactReference.query.find(dict(_id={'$in': ref_ids})):
|
20 |
try:
|
21 |
try:
|
21 |
ref = M.ArtifactReference.query.get(_id=ref_id)
|
|
|
22 |
if ref is None:
|
|
|
23 |
continue
|
|
|
24 |
artifact = ref.artifact
|
22 |
artifact = ref.artifact
|
25 |
s = solarize(artifact)
|
23 |
s = solarize(artifact)
|
26 |
if s is None:
|
24 |
if s is None:
|
27 |
continue
|
25 |
continue
|
28 |
if update_solr:
|
26 |
if update_solr:
|
29 |
g.solr.add([s])
|
27 |
solr_updates.append(s)
|
30 |
if update_refs:
|
28 |
if update_refs:
|
31 |
if isinstance(artifact, M.Snapshot):
|
29 |
if isinstance(artifact, M.Snapshot):
|
32 |
continue
|
30 |
continue
|
33 |
ref.references = [
|
31 |
ref.references = [
|
34 |
link.ref_id for link in find_shortlinks(s['text']) ]
|
32 |
link.ref_id for link in find_shortlinks(s['text']) ]
|
35 |
except Exception:
|
33 |
except Exception:
|
36 |
log.error('Error indexing artifact %s', ref_id)
|
34 |
log.error('Error indexing artifact %s', ref._id)
|
37 |
exceptions.append(sys.exc_info())
|
35 |
exceptions.append(sys.exc_info())
|
|
|
36 |
g.solr.add(solr_updates)
|
38 |
|
37 |
|
39 |
if len(exceptions) == 1:
|
38 |
if len(exceptions) == 1:
|
40 |
raise exceptions[0][0], exceptions[0][1], exceptions[0][2]
|
39 |
raise exceptions[0][0], exceptions[0][1], exceptions[0][2]
|
41 |
if exceptions:
|
40 |
if exceptions:
|
42 |
raise CompoundError(*exceptions)
|
41 |
raise CompoundError(*exceptions)
|
43 |
|
42 |
|
44 |
@task
|
43 |
@task
|
45 |
def del_artifacts(ref_ids):
|
44 |
def del_artifacts(ref_ids):
|
46 |
from allura import model as M
|
45 |
from allura import model as M
|
47 |
for ref_id in ref_ids:
|
46 |
if not ref_ids: return
|
48 |
g.solr.delete(id=ref_id)
|
47 |
solr_query = 'id:({0})'.format(' || '.join(ref_ids))
|
|
|
48 |
g.solr.delete(q=solr_query)
|
49 |
M.ArtifactReference.query.remove(dict(_id={'$in':ref_ids}))
|
49 |
M.ArtifactReference.query.remove(dict(_id={'$in':ref_ids}))
|
50 |
M.Shortlink.query.remove(dict(ref_id={'$in':ref_ids}))
|
50 |
M.Shortlink.query.remove(dict(ref_id={'$in':ref_ids}))
|
51 |
|
51 |
|
52 |
@task
|
52 |
@task
|
53 |
def commit():
|
53 |
def commit():
|