Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
535aeb80
Commit
535aeb80
authored
Aug 16, 2016
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ES] Fix of record deletion
parent
38f7f31a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
165 additions
and
6 deletions
+165
-6
app/models/concerns/elastic/application_search.rb
app/models/concerns/elastic/application_search.rb
+7
-2
app/workers/elastic_indexer_worker.rb
app/workers/elastic_indexer_worker.rb
+33
-4
spec/workers/elastic_indexer_worker_spec.rb
spec/workers/elastic_indexer_worker_spec.rb
+125
-0
No files found.
app/models/concerns/elastic/application_search.rb
View file @
535aeb80
...
...
@@ -45,7 +45,12 @@ module Elastic
after_commit
on: :destroy
do
if
current_application_settings
.
elasticsearch_indexing?
&&
self
.
searchable?
ElasticIndexerWorker
.
perform_async
(
:delete
,
self
.
class
.
to_s
,
self
.
id
)
ElasticIndexerWorker
.
perform_async
(
:delete
,
self
.
class
.
to_s
,
self
.
id
,
project_id:
self
.
es_parent
)
end
end
...
...
@@ -55,7 +60,7 @@ module Elastic
end
def
es_parent
project_id
return
project_id
if
respond_to?
(
:project_id
)
end
end
...
...
app/workers/elastic_indexer_worker.rb
View file @
535aeb80
...
...
@@ -5,6 +5,7 @@ class ElasticIndexerWorker
sidekiq_options
queue: :elasticsearch
ISSUE_TRACKED_FIELDS
=
%w(assignee_id author_id confidential)
NOT_NESTED_ENTITIES
=
[
Project
,
PersonalSnippet
,
ProjectSnippet
,
Snippet
]
def
perform
(
operation
,
class_name
,
record_id
,
options
=
{})
klass
=
class_name
.
constantize
...
...
@@ -14,7 +15,7 @@ class ElasticIndexerWorker
record
=
klass
.
find
(
record_id
)
record
.
__elasticsearch__
.
client
=
client
if
[
Project
,
PersonalSnippet
,
ProjectSnippet
,
Snippet
]
.
include?
(
klass
)
if
NOT_NESTED_ENTITIES
.
include?
(
klass
)
record
.
__elasticsearch__
.
__send__
"
#{
operation
}
_document"
else
record
.
__elasticsearch__
.
__send__
"
#{
operation
}
_document"
,
parent:
record
.
es_parent
...
...
@@ -22,7 +23,16 @@ class ElasticIndexerWorker
update_issue_notes
(
record
,
options
[
"changed_fields"
])
if
klass
==
Issue
when
/delete/
client
.
delete
index:
klass
.
index_name
,
type:
klass
.
document_type
,
id:
record_id
if
NOT_NESTED_ENTITIES
.
include?
(
klass
)
client
.
delete
index:
klass
.
index_name
,
type:
klass
.
document_type
,
id:
record_id
else
client
.
delete
(
index:
klass
.
index_name
,
type:
klass
.
document_type
,
id:
record_id
,
parent:
options
[
"project_id"
]
)
end
clear_project_indexes
(
record_id
)
if
klass
==
Project
end
...
...
@@ -30,6 +40,8 @@ class ElasticIndexerWorker
true
# Less work to do!
end
private
def
update_issue_notes
(
record
,
changed_fields
)
if
changed_fields
&&
(
changed_fields
&
ISSUE_TRACKED_FIELDS
).
any?
Note
.
import_with_parent
query:
->
{
where
(
noteable:
record
)
}
...
...
@@ -37,7 +49,12 @@ class ElasticIndexerWorker
end
def
clear_project_indexes
(
record_id
)
# Remove repository index
remove_repository_index
(
record_id
)
remove_wiki_index
(
record_id
)
remove_nested_content
(
record_id
)
end
def
remove_repository_index
(
record_id
)
client
.
delete_by_query
({
index:
Repository
.
__elasticsearch__
.
index_name
,
body:
{
...
...
@@ -49,8 +66,20 @@ class ElasticIndexerWorker
}
}
})
end
def
remove_nested_content
(
record_id
)
client
.
delete_by_query
({
index:
Project
.
__elasticsearch__
.
index_name
,
body:
{
query:
{
term:
{
"_parent"
=>
record_id
}
}
}
})
end
# Remove wiki index
def
remove_wiki_index
(
record_id
)
client
.
delete_by_query
({
index:
ProjectWiki
.
__elasticsearch__
.
index_name
,
body:
{
...
...
spec/workers/elastic_indexer_worker_spec.rb
0 → 100644
View file @
535aeb80
require
'spec_helper'
describe
ElasticIndexerWorker
,
elastic:
true
do
include
Gitlab
::
CurrentSettings
subject
{
described_class
.
new
}
before
do
Elasticsearch
::
Model
.
client
=
Elasticsearch
::
Client
.
new
(
host:
current_application_settings
.
elasticsearch_host
,
port:
current_application_settings
.
elasticsearch_port
)
Gitlab
::
Elastic
::
Helper
.
create_empty_index
end
after
do
Gitlab
::
Elastic
::
Helper
.
delete_index
end
Sidekiq
::
Testing
.
disable!
do
describe
'Indexing new records'
do
it
'indexes a project'
do
project
=
create
:empty_project
expect
do
subject
.
perform
(
"index"
,
"Project"
,
project
.
id
)
Gitlab
::
Elastic
::
Helper
.
refresh_index
end
.
to
change
{
Elasticsearch
::
Model
.
search
(
'*'
).
records
.
size
}.
by
(
1
)
end
it
'indexes an issue'
do
issue
=
create
:issue
expect
do
subject
.
perform
(
"index"
,
"Issue"
,
issue
.
id
)
Gitlab
::
Elastic
::
Helper
.
refresh_index
end
.
to
change
{
Elasticsearch
::
Model
.
search
(
'*'
).
records
.
size
}.
by
(
1
)
end
it
'indexes a note'
do
note
=
create
:note
expect
do
subject
.
perform
(
"index"
,
"Note"
,
note
.
id
)
Gitlab
::
Elastic
::
Helper
.
refresh_index
end
.
to
change
{
Elasticsearch
::
Model
.
search
(
'*'
).
records
.
size
}.
by
(
1
)
end
it
'indexes a milestone'
do
milestone
=
create
:milestone
expect
do
subject
.
perform
(
"index"
,
"Milestone"
,
milestone
.
id
)
Gitlab
::
Elastic
::
Helper
.
refresh_index
end
.
to
change
{
Elasticsearch
::
Model
.
search
(
'*'
).
records
.
size
}.
by
(
1
)
end
it
'indexes a merge request'
do
merge_request
=
create
:merge_request
expect
do
subject
.
perform
(
"index"
,
"MergeRequest"
,
merge_request
.
id
)
Gitlab
::
Elastic
::
Helper
.
refresh_index
end
.
to
change
{
Elasticsearch
::
Model
.
search
(
'*'
).
records
.
size
}.
by
(
1
)
end
end
describe
'Updating index'
do
it
'updates a project'
do
project
=
create
:empty_project
subject
.
perform
(
"index"
,
"Project"
,
project
.
id
)
project
.
update
(
name:
"new"
)
expect
do
subject
.
perform
(
"update"
,
"Project"
,
project
.
id
)
Gitlab
::
Elastic
::
Helper
.
refresh_index
end
.
to
change
{
Elasticsearch
::
Model
.
search
(
'new'
).
records
.
size
}.
by
(
1
)
end
it
'updates an issue'
do
issue
=
create
:issue
subject
.
perform
(
"index"
,
"Issue"
,
issue
.
id
)
issue
.
update
(
title:
"new"
)
expect
do
subject
.
perform
(
"update"
,
"Issue"
,
issue
.
id
)
Gitlab
::
Elastic
::
Helper
.
refresh_index
end
.
to
change
{
Elasticsearch
::
Model
.
search
(
'new'
).
records
.
size
}.
by
(
1
)
end
it
'updates a note'
do
note
=
create
:note
subject
.
perform
(
"index"
,
"Note"
,
note
.
id
)
note
.
update
(
note:
'new'
)
expect
do
subject
.
perform
(
"update"
,
"Note"
,
note
.
id
)
Gitlab
::
Elastic
::
Helper
.
refresh_index
end
.
to
change
{
Elasticsearch
::
Model
.
search
(
'new'
).
records
.
size
}.
by
(
1
)
end
it
'updates a milestone'
do
milestone
=
create
:milestone
subject
.
perform
(
"index"
,
"Milestone"
,
milestone
.
id
)
milestone
.
update
(
title:
'new'
)
expect
do
subject
.
perform
(
"update"
,
"Milestone"
,
milestone
.
id
)
Gitlab
::
Elastic
::
Helper
.
refresh_index
end
.
to
change
{
Elasticsearch
::
Model
.
search
(
'new'
).
records
.
size
}.
by
(
1
)
end
it
'updates a merge request'
do
merge_request
=
create
:merge_request
subject
.
perform
(
"index"
,
"MergeRequest"
,
merge_request
.
id
)
merge_request
.
update
(
title:
'new'
)
expect
do
subject
.
perform
(
"index"
,
"MergeRequest"
,
merge_request
.
id
)
Gitlab
::
Elastic
::
Helper
.
refresh_index
end
.
to
change
{
Elasticsearch
::
Model
.
search
(
'new'
).
records
.
size
}.
by
(
1
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment