Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
elasticsearch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cubicweb
cubes
elasticsearch
Commits
a6137bc159fb
Commit
a6137bc159fb
authored
8 years ago
by
Samuel Trégouët
Browse files
Options
Downloads
Patches
Plain Diff
[hook] handle delete entity
parent
3d097513f4dd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hooks.py
+16
-10
16 additions, 10 deletions
hooks.py
with
16 additions
and
10 deletions
hooks.py
+
16
−
10
View file @
a6137bc1
...
...
@@ -39,7 +39,7 @@
__regid__
=
'
elasticsearch.contentupdatetoes
'
__select__
=
hook
.
Hook
.
__select__
&
score_entity
(
entity_indexable
)
events
=
(
'
after_update_entity
'
,
'
after_add_entity
'
)
events
=
(
'
after_update_entity
'
,
'
after_add_entity
'
,
'
after_delete_entity
'
)
category
=
'
es
'
def
__call__
(
self
):
...
...
@@ -76,8 +76,18 @@
log
.
error
(
'
no connection to ES (not configured) skip ES indexing
'
)
return
for
entity
in
self
.
get_data
():
kwargs
=
dict
(
index
=
indexer
.
index_name
,
id
=
entity
.
eid
,
doc_type
=
entity
.
cw_etype
)
if
self
.
cnx
.
deleted_in_transaction
(
entity
.
eid
):
try
:
# TODO option for async ?
es
.
delete
(
**
kwargs
)
except
(
ConnectionError
,
ProtocolError
):
log
.
debug
(
'
Failed to index in hook, could not connect to ES
'
)
continue
rql
=
fulltext_indexable_rql
(
entity
.
cw_etype
,
entity
.
_cw
.
vreg
.
schema
,
eid
=
entity
.
eid
)
indexable_entity
=
self
.
cnx
.
execute
(
rql
).
one
()
serializer
=
indexable_entity
.
cw_adapt_to
(
'
IFullTextIndexSerializable
'
)
...
...
@@ -79,8 +89,12 @@
rql
=
fulltext_indexable_rql
(
entity
.
cw_etype
,
entity
.
_cw
.
vreg
.
schema
,
eid
=
entity
.
eid
)
indexable_entity
=
self
.
cnx
.
execute
(
rql
).
one
()
serializer
=
indexable_entity
.
cw_adapt_to
(
'
IFullTextIndexSerializable
'
)
json
=
serializer
.
serialize
()
kwargs
[
'
body
'
]
=
json
=
serializer
.
serialize
()
if
json
.
get
(
'
parent
'
):
kwargs
[
'
parent
'
]
=
json
.
pop
(
'
parent
'
)
else
:
# TODO only for types that have parents
kwargs
[
'
routing
'
]
=
entity
.
eid
try
:
# TODO option pour coté async ? thread
...
...
@@ -85,13 +99,5 @@
try
:
# TODO option pour coté async ? thread
kwargs
=
dict
(
index
=
indexer
.
index_name
,
id
=
entity
.
eid
,
doc_type
=
entity
.
cw_etype
,
body
=
json
)
if
json
.
get
(
'
parent
'
):
kwargs
[
'
parent
'
]
=
json
.
pop
(
'
parent
'
)
else
:
# TODO only for types that have parents
kwargs
[
'
routing
'
]
=
entity
.
eid
es
.
index
(
**
kwargs
)
except
(
ConnectionError
,
ProtocolError
):
log
.
debug
(
'
Failed to index in hook, could not connect to ES
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment