Parent: [a28a7b] (diff)

Child: [da44c9] (diff)

Download this file

index_tasks.py    54 lines (45 with data), 1.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys
import logging
from contextlib import contextmanager
from pylons import g
from allura.lib.decorators import task
from allura.lib.exceptions import CompoundError
log = logging.getLogger(__name__)
@task
def add_artifacts(ref_ids):
'''Add the referenced artifacts to SOLR and shortlinks'''
from allura import model as M
from allura.lib.search import find_shortlinks, solarize
exceptions = []
with _indexing_disabled(M.session.artifact_orm_session._get()):
for ref_id in ref_ids:
try:
ref = M.ArtifactReference.query.get(_id=ref_id)
artifact = ref.artifact
s = solarize(artifact)
if s is None: continue
g.solr.add([s])
if isinstance(artifact, M.Snapshot): continue
ref.references = [
link.ref_id for link in find_shortlinks(s['text']) ]
except Exception:
exceptions.append(sys.exc_info())
if exceptions:
raise CompoundError(*exceptions)
@task
def del_artifacts(ref_ids):
from allura import model as M
for ref_id in ref_ids:
g.solr.delete(id=ref_id)
M.ArtifactReference.query.remove(dict(_id={'$in':ref_ids}))
M.Shortlink.query.remove(dict(ref_id={'$in':ref_ids}))
@task
def commit():
g.solr.commit()
@contextmanager
def _indexing_disabled(session):
session.disable_artifact_index = session.skip_mod_date = True
try:
yield session
finally:
session.disable_artifact_index = session.skip_mod_date = False