diff options
Diffstat (limited to 'app/graphql/batch_loaders/award_emoji_votes_batch_loader.rb')
-rw-r--r-- | app/graphql/batch_loaders/award_emoji_votes_batch_loader.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/app/graphql/batch_loaders/award_emoji_votes_batch_loader.rb b/app/graphql/batch_loaders/award_emoji_votes_batch_loader.rb new file mode 100644 index 00000000000..c1b35d3eaf7 --- /dev/null +++ b/app/graphql/batch_loaders/award_emoji_votes_batch_loader.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module BatchLoaders + module AwardEmojiVotesBatchLoader + private + + def load_votes(object, vote_type) + BatchLoader::GraphQL.for(object.id).batch(key: "#{object.issuing_parent_id}-#{vote_type}") do |ids, loader, args| + counts = AwardEmoji.votes_for_collection(ids, object.class.name).named(vote_type).index_by(&:awardable_id) + + ids.each do |id| + loader.call(id, counts[id]&.count || 0) + end + end + end + + def authorized_resource?(object) + Ability.allowed?(current_user, "read_#{object.to_ability_name}".to_sym, object) + end + end +end |