Skip to content

Commit

Permalink
CV2-5225: apply nested_objects_limit on tags and requests
Browse files Browse the repository at this point in the history
  • Loading branch information
melsawy committed Sep 9, 2024
1 parent 5c74496 commit c533024
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 37 deletions.
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
7 changes: 0 additions & 7 deletions app/models/concerns/annotation_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,6 @@ def custom_permissions(ability = nil)
perms["destroy Smooch"] = ability.can?(:destroy, self) if self.annotation_type == 'smooch'
perms
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
end

module ClassMethods
Expand Down
24 changes: 0 additions & 24 deletions test/controllers/elastic_search_7_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,29 +300,5 @@ def setup
end
end

test "should ignore index task responses that exceeds nested objects limit" do
team = create_team
stub_configs({ 'nested_objects_limit' => 2 }) do
tt = create_team_task team_id: team.id, type: 'single_choice', options: ['ans_a', 'ans_b', 'ans_c']
tt2 = create_team_task team_id: team.id, type: 'single_choice', options: ['ans_aa', 'ans_bb', 'ans_cc']
tt3 = create_team_task team_id: team.id, type: 'free_text'
pm = create_project_media team: team, disable_es_callbacks: false
pm_tt = pm.annotations('task').select{|t| t.team_task_id == tt.id}.last
pm_tt.response = { annotation_type: 'task_response_single_choice', set_fields: { response_single_choice: 'ans_a' }.to_json }.to_json
pm_tt.save!
pm_tt2 = pm.annotations('task').select{|t| t.team_task_id == tt2.id}.last
pm_tt2.response = { annotation_type: 'task_response_single_choice', set_fields: { response_single_choice: 'ans_aa' }.to_json }.to_json
pm_tt2.save!
pm_tt3 = pm.annotations('task').select{|t| t.team_task_id == tt3.id}.last
pm_tt3.response = { annotation_type: 'task_response_free_text', set_fields: { response_free_text: 'Foo by Sawy' }.to_json }.to_json
pm_tt3.save!
sleep 2
es = $repository.find(pm.get_es_doc_id)
task_responses = es['task_responses']
# TODO: fix the test
# assert_equal 2, task_responses.size
end
end

# Please add new tests to test/controllers/elastic_search_8_test.rb
end
6 changes: 0 additions & 6 deletions test/controllers/elastic_search_9_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ def setup
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
c = create_comment annotated: pm, disable_es_callbacks: false
c2 = create_comment annotated: pm, disable_es_callbacks: false
c3 = create_comment annotated: pm, disable_es_callbacks: false
sleep 2
es = $repository.find(pm.get_es_doc_id)
requests = es['requests']
Expand All @@ -251,9 +248,6 @@ def setup
tags = es['tags']
assert_equal 2, tags.size
assert_equal [t.id, t2.id], tags.collect{|i| i['id']}.sort
comments = es['comments']
assert_equal 2, comments.size
assert_equal [c.id, c2.id], comments.collect{|i| i['id']}.sort
end
end

Expand Down

0 comments on commit c533024

Please sign in to comment.