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
  • Loading branch information
melsawy committed Sep 8, 2024
1 parent 4dcbe5d commit 763e51c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
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/concerns/annotation_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ 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
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

0 comments on commit 763e51c

Please sign in to comment.