PERF: tag groups index query

This commit is contained in:
Neil Lalonde 2016-07-15 17:16:13 -04:00
parent 4d27d7e1d3
commit a74606c87c
2 changed files with 2 additions and 2 deletions

View File

@ -4,7 +4,7 @@ class TagGroupsController < ApplicationController
before_filter :fetch_tag_group, only: [:show, :update, :destroy]
def index
tag_groups = TagGroup.order('name ASC').includes(:parent_tag).all
tag_groups = TagGroup.order('name ASC').includes(:parent_tag).preload(:tags).all
serializer = ActiveModel::ArraySerializer.new(tag_groups, each_serializer: TagGroupSerializer, root: 'tag_groups')
respond_to do |format|
format.html do

View File

@ -2,7 +2,7 @@ class TagGroupSerializer < ApplicationSerializer
attributes :id, :name, :tag_names, :parent_tag_name, :one_per_topic
def tag_names
object.tags.pluck(:name).sort
object.tags.map(&:name).sort
end
def parent_tag_name