users: do dumb caching of these big user trees

This commit is contained in:
Carl Chenet 2017-05-16 19:48:01 +02:00
parent 432977c087
commit 60ec1d6250

View file

@ -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