mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
Add support for preloaded custom_fields on Group
This commit is contained in:
parent
76a217c4bc
commit
d182f0f2d1
2 changed files with 11 additions and 0 deletions
|
@ -30,6 +30,10 @@ class GroupsController < ApplicationController
|
||||||
count = groups.count
|
count = groups.count
|
||||||
groups = groups.offset(page * page_size).limit(page_size)
|
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)
|
group_user_ids = GroupUser.where(group: groups, user: current_user).pluck(:group_id)
|
||||||
|
|
||||||
render_json_dump(
|
render_json_dump(
|
||||||
|
@ -310,6 +314,10 @@ class GroupsController < ApplicationController
|
||||||
groups = groups.where(automatic: false)
|
groups = groups.where(automatic: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Group.preloaded_custom_field_names.present?
|
||||||
|
Group.preload_custom_fields(groups, Group.preloaded_custom_field_names)
|
||||||
|
end
|
||||||
|
|
||||||
render_serialized(groups, BasicGroupSerializer)
|
render_serialized(groups, BasicGroupSerializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,9 @@ class Group < ActiveRecord::Base
|
||||||
include HasCustomFields
|
include HasCustomFields
|
||||||
include AnonCacheInvalidator
|
include AnonCacheInvalidator
|
||||||
|
|
||||||
|
cattr_accessor :preloaded_custom_field_names
|
||||||
|
self.preloaded_custom_field_names = Set.new
|
||||||
|
|
||||||
has_many :category_groups, dependent: :destroy
|
has_many :category_groups, dependent: :destroy
|
||||||
has_many :group_users, dependent: :destroy
|
has_many :group_users, dependent: :destroy
|
||||||
has_many :group_mentions, dependent: :destroy
|
has_many :group_mentions, dependent: :destroy
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue