|
a/Allura/allura/model/session.py |
|
b/Allura/allura/model/session.py |
|
... |
|
... |
28 |
elif st.status == st.deleted:
|
28 |
elif st.status == st.deleted:
|
29 |
self.objects_deleted = [ obj ]
|
29 |
self.objects_deleted = [ obj ]
|
30 |
|
30 |
|
31 |
def after_flush(self, obj=None):
|
31 |
def after_flush(self, obj=None):
|
32 |
"Update artifact references, and add/update this artifact to solr"
|
32 |
"Update artifact references, and add/update this artifact to solr"
|
33 |
import allura.tasks.index_tasks
|
|
|
34 |
if not getattr(self.session, 'disable_artifact_index', False):
|
33 |
if not getattr(self.session, 'disable_artifact_index', False):
|
35 |
from pylons import g
|
34 |
from pylons import g
|
36 |
from .index import ArtifactReference, Shortlink
|
35 |
from .index import ArtifactReference, Shortlink
|
37 |
from .session import main_orm_session
|
36 |
from .session import main_orm_session
|
38 |
# Ensure artifact references & shortlinks exist for new objects
|
37 |
# Ensure artifact references & shortlinks exist for new objects
|
|
... |
|
... |
45 |
Shortlink.from_artifact(obj)
|
44 |
Shortlink.from_artifact(obj)
|
46 |
# Flush shortlinks
|
45 |
# Flush shortlinks
|
47 |
main_orm_session.flush()
|
46 |
main_orm_session.flush()
|
48 |
except Exception:
|
47 |
except Exception:
|
49 |
log.exception("Failed to update artifact references. Is this a borked project migration?")
|
48 |
log.exception("Failed to update artifact references. Is this a borked project migration?")
|
50 |
# Post delete and add indexing operations
|
49 |
self.update_index(self.objects_deleted, arefs)
|
51 |
if self.objects_deleted:
|
|
|
52 |
allura.tasks.index_tasks.del_artifacts.post(
|
|
|
53 |
[ obj.index_id() for obj in self.objects_deleted ])
|
|
|
54 |
if arefs:
|
|
|
55 |
allura.tasks.index_tasks.add_artifacts.post([ aref._id for aref in arefs ])
|
|
|
56 |
for obj in self.objects_added:
|
50 |
for obj in self.objects_added:
|
57 |
g.zarkov_event('create', extra=obj.index_id())
|
51 |
g.zarkov_event('create', extra=obj.index_id())
|
58 |
for obj in self.objects_modified:
|
52 |
for obj in self.objects_modified:
|
59 |
g.zarkov_event('modify', extra=obj.index_id())
|
53 |
g.zarkov_event('modify', extra=obj.index_id())
|
60 |
for obj in self.objects_deleted:
|
54 |
for obj in self.objects_deleted:
|
61 |
g.zarkov_event('delete', extra=obj.index_id())
|
55 |
g.zarkov_event('delete', extra=obj.index_id())
|
62 |
self.objects_added = []
|
56 |
self.objects_added = []
|
63 |
self.objects_modified = []
|
57 |
self.objects_modified = []
|
64 |
self.objects_deleted = []
|
58 |
self.objects_deleted = []
|
|
|
59 |
|
|
|
60 |
def update_index(self, objects_deleted, arefs):
|
|
|
61 |
# Post delete and add indexing operations
|
|
|
62 |
from allura.tasks import index_tasks
|
|
|
63 |
if objects_deleted:
|
|
|
64 |
index_tasks.del_artifacts.post(
|
|
|
65 |
[obj.index_id() for obj in objects_deleted])
|
|
|
66 |
if arefs:
|
|
|
67 |
index_tasks.add_artifacts.post([aref._id for aref in arefs])
|
65 |
|
68 |
|
66 |
main_doc_session = Session.by_name('main')
|
69 |
main_doc_session = Session.by_name('main')
|
67 |
project_doc_session = Session.by_name('project')
|
70 |
project_doc_session = Session.by_name('project')
|
68 |
main_orm_session = ThreadLocalORMSession(main_doc_session)
|
71 |
main_orm_session = ThreadLocalORMSession(main_doc_session)
|
69 |
project_orm_session = ThreadLocalORMSession(project_doc_session)
|
72 |
project_orm_session = ThreadLocalORMSession(project_doc_session)
|