optimize recent_content_list

This commit is contained in:
Andrew Brown 2018-09-24 12:56:03 -05:00
parent 6ae67eab3c
commit bfbc017e28
2 changed files with 7 additions and 10 deletions

View File

@ -96,15 +96,13 @@ module HasContent
# [..., ..., ...]
def recent_content_list
content_types = Rails.application.config.content_types[:all]
@user_recent_content_list ||= content_types.flat_map { |klass|
klass.where(user_id: id)
.order(updated_at: :desc)
.limit(10)
}.sort_by(&:updated_at)
.last(10)
.reverse
recently_changed_attributes = Attribute.where(user: self)
.order('updated_at desc')
.group([:entity_type, :entity_id])
.limit(10)
@user_recent_content_list = recently_changed_attributes.map do |attr|
attr.entity_type.constantize.find_by(id: attr.entity_id)
end.compact
end
end
end

View File

@ -109,7 +109,6 @@
<%= link_to main_app.customization_content_types_path do %>
<i class="material-icons black-text">add</i>
Customize pages
<!-- <span class="new badge"></span> -->
<% end %>
</li>