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
076cb80f
Commit
076cb80f
authored
Mar 06, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Robustify reading attributes for elasticsearch
parent
6e519f8c
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
46 additions
and
21 deletions
+46
-21
app/models/concerns/elastic/application_search.rb
app/models/concerns/elastic/application_search.rb
+10
-0
app/models/concerns/elastic/issues_search.rb
app/models/concerns/elastic/issues_search.rb
+1
-1
app/models/concerns/elastic/merge_requests_search.rb
app/models/concerns/elastic/merge_requests_search.rb
+1
-1
app/models/concerns/elastic/milestones_search.rb
app/models/concerns/elastic/milestones_search.rb
+9
-3
app/models/concerns/elastic/notes_search.rb
app/models/concerns/elastic/notes_search.rb
+1
-1
app/models/concerns/elastic/projects_search.rb
app/models/concerns/elastic/projects_search.rb
+1
-1
app/models/concerns/elastic/snippets_search.rb
app/models/concerns/elastic/snippets_search.rb
+19
-14
changelogs/unreleased-ee/1840-robustify-es-db-indexing.yml
changelogs/unreleased-ee/1840-robustify-es-db-indexing.yml
+4
-0
No files found.
app/models/concerns/elastic/application_search.rb
View file @
076cb80f
...
...
@@ -74,6 +74,16 @@ module Elastic
def
es_parent
project_id
if
respond_to?
(
:project_id
)
end
# Some attributes are actually complicated methods. Bad data can cause
# them to raise exceptions. When this happens, we still want the remainder
# of the object to be saved, so silently swallow the errors
def
safely_read_attribute_for_elasticsearch
(
attr_name
)
send
(
attr_name
)
rescue
=>
err
logger
.
warn
(
"Elasticsearch failed to read
#{
attr_name
}
for
#{
self
.
class
}
#{
self
.
id
}
:
#{
err
}
"
)
nil
end
end
module
ClassMethods
...
...
app/models/concerns/elastic/issues_search.rb
View file @
076cb80f
...
...
@@ -27,7 +27,7 @@ module Elastic
# We don't use as_json(only: ...) because it calls all virtual and serialized attributtes
# https://gitlab.com/gitlab-org/gitlab-ee/issues/349
[
:id
,
:iid
,
:title
,
:description
,
:created_at
,
:updated_at
,
:state
,
:project_id
,
:author_id
,
:assignee_id
,
:confidential
].
each
do
|
attr
|
data
[
attr
.
to_s
]
=
s
elf
.
send
(
attr
)
data
[
attr
.
to_s
]
=
s
afely_read_attribute_for_elasticsearch
(
attr
)
end
data
...
...
app/models/concerns/elastic/merge_requests_search.rb
View file @
076cb80f
...
...
@@ -45,7 +45,7 @@ module Elastic
:target_project_id
,
:author_id
].
each
do
|
attr
|
data
[
attr
.
to_s
]
=
s
elf
.
send
(
attr
)
data
[
attr
.
to_s
]
=
s
afely_read_attribute_for_elasticsearch
(
attr
)
end
data
...
...
app/models/concerns/elastic/milestones_search.rb
View file @
076cb80f
...
...
@@ -17,9 +17,15 @@ module Elastic
end
def
as_indexed_json
(
options
=
{})
as_json
(
only:
[
:id
,
:title
,
:description
,
:project_id
,
:created_at
,
:updated_at
]
)
# We don't use as_json(only: ...) because it calls all virtual and serialized attributtes
# https://gitlab.com/gitlab-org/gitlab-ee/issues/349
data
=
{}
[
:id
,
:title
,
:description
,
:project_id
,
:created_at
,
:updated_at
].
each
do
|
attr
|
data
[
attr
.
to_s
]
=
safely_read_attribute_for_elasticsearch
(
attr
)
end
data
end
def
self
.
nested?
...
...
app/models/concerns/elastic/notes_search.rb
View file @
076cb80f
...
...
@@ -26,7 +26,7 @@ module Elastic
# We don't use as_json(only: ...) because it calls all virtual and serialized attributtes
# https://gitlab.com/gitlab-org/gitlab-ee/issues/349
[
:id
,
:note
,
:project_id
,
:created_at
,
:updated_at
].
each
do
|
attr
|
data
[
attr
.
to_s
]
=
s
elf
.
send
(
attr
)
data
[
attr
.
to_s
]
=
s
afely_read_attribute_for_elasticsearch
(
attr
)
end
if
noteable
.
is_a?
(
Issue
)
...
...
app/models/concerns/elastic/projects_search.rb
View file @
076cb80f
...
...
@@ -46,7 +46,7 @@ module Elastic
:name_with_namespace
,
:path_with_namespace
].
each
do
|
attr
|
data
[
attr
.
to_s
]
=
s
elf
.
send
(
attr
)
data
[
attr
.
to_s
]
=
s
afely_read_attribute_for_elasticsearch
(
attr
)
end
data
...
...
app/models/concerns/elastic/snippets_search.rb
View file @
076cb80f
...
...
@@ -22,20 +22,25 @@ module Elastic
end
def
as_indexed_json
(
options
=
{})
as_json
({
only:
[
:id
,
:title
,
:file_name
,
:content
,
:created_at
,
:updated_at
,
:state
,
:project_id
,
:author_id
,
:visibility_level
]
})
# We don't use as_json(only: ...) because it calls all virtual and serialized attributtes
# https://gitlab.com/gitlab-org/gitlab-ee/issues/349
data
=
{}
[
:id
,
:title
,
:file_name
,
:content
,
:created_at
,
:updated_at
,
:project_id
,
:author_id
,
:visibility_level
].
each
do
|
attr
|
data
[
attr
.
to_s
]
=
safely_read_attribute_for_elasticsearch
(
attr
)
end
data
end
def
self
.
elastic_search
(
query
,
options:
{})
...
...
changelogs/unreleased-ee/1840-robustify-es-db-indexing.yml
0 → 100644
View file @
076cb80f
---
title
:
Robustify reading attributes for elasticsearch
merge_request
:
1365
author
:
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