@@ -159,16 +159,32 @@ def search(query:)
159159 CheckSearch . new ( query , context [ :file ] , team &.id )
160160 end
161161
162- field :dynamic_annotation_field , DynamicAnnotationFieldType , null : true , deprecation_reason : "The field is deprecated" do
162+ field :dynamic_annotation_field , DynamicAnnotationFieldType , null : true do
163163 argument :query , GraphQL ::Types ::String , required : true
164164 argument :only_cache , GraphQL ::Types ::Boolean , required : false , camelize : false
165165 end
166166
167167 def dynamic_annotation_field ( query :, only_cache : nil )
168- # This field was previously used to query DynamicAnnotation::Field for the Check Slack Bot integration.
169- # It was not used by Check itself and required global permissions to read the field across all teams.
170- # So, I removed the global permission and updated the callback to return nil to avoid breaking the Check Slack Bot integration.
171- nil
168+ ability = context [ :ability ] || Ability . new
169+ if ability . can? ( :find_by_json_fields , DynamicAnnotation ::Field . new )
170+ cache_key =
171+ "dynamic-annotation-field-" + Digest ::MD5 . hexdigest ( query )
172+ obj = nil
173+ if Rails . cache . read ( cache_key ) || only_cache
174+ obj =
175+ DynamicAnnotation ::Field . where (
176+ id : Rails . cache . read ( cache_key ) . to_i
177+ ) . last
178+ else
179+ query = JSON . parse ( query )
180+ json = query . delete ( "json" )
181+ obj = DynamicAnnotation ::Field . where ( query )
182+ obj = obj . find_in_json ( json ) unless json . blank?
183+ obj = obj . last
184+ Rails . cache . write ( cache_key , obj &.id )
185+ end
186+ obj
187+ end
172188 end
173189
174190 field :feed_invitation , FeedInvitationType , description : 'Information about a feed invitation, given its database ID or feed database ID (and then the current user email is used)' , null : true do
0 commit comments