Skip to content

Commit

Permalink
CSV-5225: ignore nested documents that exceeds nested_objects_limit (#…
Browse files Browse the repository at this point in the history
…2025)

* CSV-5225: ignore nested documents that exceeds nested_objects_limit

* CV2-5225: add tests

* CV2-5225: cleanup

* CV2-5225: apply nested_objects_limit on tags and requests
  • Loading branch information
melsawy authored Sep 9, 2024
1 parent 4dcbe5d commit c955714
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
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?
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

0 comments on commit c955714

Please sign in to comment.