From 60ec1d625091539b9966ddd65feed1b0422a1787 Mon Sep 17 00:00:00 2001 From: Carl Chenet Date: Tue, 16 May 2017 19:48:01 +0200 Subject: [PATCH] users: do dumb caching of these big user trees --- app/controllers/users_controller.rb | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4371d25..4bcf869 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -16,11 +16,16 @@ class UsersController < ApplicationController def tree @title = I18n.t 'controllers.users_controller.usertitle' + newest_user = User.last.id + if params[:by].to_s == "karma" - @users = User.order("karma DESC, id ASC").to_a - @user_count = @users.length - @title << " By Karma" - render :action => "list" + render :text => Rails.cache.fetch("users_by_karma_#{newest_user}", + :expires_in => (60 * 60 * 24)) { + @users = User.order("karma DESC, id ASC").to_a + @user_count = @users.length + @title << " By Karma" + render_to_string :action => "list" + } elsif params[:moderators] @users = User.where("is_admin = ? OR is_moderator = ?", true, true). order("id ASC").to_a @@ -28,10 +33,14 @@ class UsersController < ApplicationController @title = "Moderators and Administrators" render :action => "list" else - users = User.order("id DESC").to_a - @user_count = users.length - @users_by_parent = users.group_by(&:invited_by_user_id) - @newest = User.order("id DESC").limit(10) + render :text => Rails.cache.fetch("users_tree_#{newest_user}", + :expires_in => (60 * 60 * 24)) { + users = User.order("id DESC").to_a + @user_count = users.length + @users_by_parent = users.group_by(&:invited_by_user_id) + @newest = User.order("id DESC").limit(10) + render_to_string :action => "tree" + } end end