From d182f0f2d1e94ce52907d37f803a428945b19e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 8 Aug 2017 15:45:27 +0200 Subject: [PATCH] Add support for preloaded custom_fields on Group --- app/controllers/groups_controller.rb | 8 ++++++++ app/models/group.rb | 3 +++ 2 files changed, 11 insertions(+) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index d73b87e4d6c..b06fd25a715 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -30,6 +30,10 @@ class GroupsController < ApplicationController count = groups.count groups = groups.offset(page * page_size).limit(page_size) + if Group.preloaded_custom_field_names.present? + Group.preload_custom_fields(groups, Group.preloaded_custom_field_names) + end + group_user_ids = GroupUser.where(group: groups, user: current_user).pluck(:group_id) render_json_dump( @@ -310,6 +314,10 @@ class GroupsController < ApplicationController groups = groups.where(automatic: false) end + if Group.preloaded_custom_field_names.present? + Group.preload_custom_fields(groups, Group.preloaded_custom_field_names) + end + render_serialized(groups, BasicGroupSerializer) end diff --git a/app/models/group.rb b/app/models/group.rb index f137ec8931c..2d4d82f5814 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -6,6 +6,9 @@ class Group < ActiveRecord::Base include HasCustomFields include AnonCacheInvalidator + cattr_accessor :preloaded_custom_field_names + self.preloaded_custom_field_names = Set.new + has_many :category_groups, dependent: :destroy has_many :group_users, dependent: :destroy has_many :group_mentions, dependent: :destroy