Created
August 21, 2015 12:48
-
-
Save 5minpause/c899b2feb5796af39960 to your computer and use it in GitHub Desktop.
After optimizations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
collection_action :load_overviewtree_as_json do | |
if params[:root_id].present? | |
objects = Goldencobra::Article.where(id: params[:root_id]).first.children.reorder(:url_name) | |
cache_key ||= ["articles", params[:root_id], objects.map(&:id), objects.maximum(:updated_at)] | |
articles = Rails.cache.fetch(cache_key) do | |
Goldencobra::Article.find(params[:root_id]) | |
.children.reorder(:url_name).as_json(only: [:id, :url_path, :title, :url_name], | |
methods: [:has_children, :restricted]) | |
end | |
else | |
objects = Goldencobra::Article.reorder(:url_name).roots | |
cache_key ||= ["articles", objects.map(&:id), objects.maximum(:updated_at)] | |
articles = Rails.cache.fetch(cache_key) do | |
Goldencobra::Article.order(:url_name).roots.as_json(only: [:id, :url_path, :title, :url_name], | |
methods: [:has_children, :restricted]) | |
end | |
end | |
render json: Oj.dump({"articles" => articles}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment