Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV-5225: ignore nested documents that exceeds nested_objects_limit #2025

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/lib/check_elastic_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def get_fresh_value(data)

def add_update_nested_obj(options)
return if self.disable_es_callbacks || RequestStore.store[:disable_es_callbacks]
return if options[:op] == 'create' && self.respond_to?(:hit_nested_objects_limit?) && self.hit_nested_objects_limit?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Only happens when the operation is "create"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes as create add a new object to nested_object

model = { klass: self.class.name, id: self.id }
ElasticSearchWorker.perform_in(1.second, YAML::dump(model), YAML::dump(options), 'create_update_doc_nested')
end
Expand Down
7 changes: 7 additions & 0 deletions app/models/annotations/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ def self.run_bulk_create_callbacks(ids_json, pmids_json)
ProjectMedia.where(id: pmids).find_each { |pm| pm.tags_as_sentence }
end

def hit_nested_objects_limit?
ret = false
pm = self.project_media
ret = pm.get_annotations(self.annotation_type).count > CheckConfig.get('nested_objects_limit', 10000, :integer) unless pm.nil?
ret
end

private

def get_tag_text_reference
Expand Down
5 changes: 5 additions & 0 deletions app/models/tipline_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def associated_graphql_id
Base64.encode64("#{self.associated_type}/#{self.associated_id}")
end

def hit_nested_objects_limit?
associated = self.associated
associated.tipline_requests.count > CheckConfig.get('nested_objects_limit', 10000, :integer)
end

private

def set_team_and_user
Expand Down
23 changes: 22 additions & 1 deletion test/controllers/elastic_search_9_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def setup
test "shoud add team filter by default" do
t = create_team
t2 = create_team
pm1 = create_project_media team: t, quote: 'test', disable_es_callbacks: false
pm1 = create_project_media team: t, quote: 'test', disable_es_callbacks: false
pm2 = create_project_media team: t2, quote: 'test', disable_es_callbacks: false
ProjectMedia.where(id: [pm1.id, pm2.id]).update_all(project_id: nil)
options = {
Expand All @@ -230,5 +230,26 @@ def setup
Team.unstub(:current)
end

test "should ignore index document that exceeds nested objects limit" do
team = create_team
pm = create_project_media team: team
stub_configs({ 'nested_objects_limit' => 2 }) do
tr = create_tipline_request associated: pm, disable_es_callbacks: false
tr2 = create_tipline_request associated: pm, disable_es_callbacks: false
tr3 = create_tipline_request associated: pm, disable_es_callbacks: false
t = create_tag annotated: pm, disable_es_callbacks: false
t2 = create_tag annotated: pm, disable_es_callbacks: false
t3 = create_tag annotated: pm, disable_es_callbacks: false
sleep 2
es = $repository.find(pm.get_es_doc_id)
requests = es['requests']
assert_equal 2, requests.size
assert_equal [tr.id, tr2.id], requests.collect{|r| r['id']}.sort
tags = es['tags']
assert_equal 2, tags.size
assert_equal [t.id, t2.id], tags.collect{|i| i['id']}.sort
end
end

# Please add new tests to test/controllers/elastic_search_10_test.rb
end
Loading