From 21a3763f0f693fac46ec608c8e201bae25a4c193 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 5 Nov 2022 16:13:27 -0500 Subject: [PATCH] users: set archives DB timeout on profile pages. Fixes profile pages potentially hanging for 60+ seconds if the archives database is slow to respond. --- app/controllers/users_controller.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8986c1272..9dc0639f9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3,6 +3,8 @@ class UsersController < ApplicationController respond_to :html, :xml, :json + around_action :set_timeout, only: [:profile, :show] + rate_limit :create, rate: 1.0/5.minutes, burst: 10 def new @@ -119,6 +121,13 @@ class UsersController < ApplicationController private + def set_timeout + PostVersion.connection.execute("SET statement_timeout = #{CurrentUser.user.statement_timeout}") + yield + ensure + PostVersion.connection.execute("SET statement_timeout = 0") + end + def item_matches_params(user) if params[:search][:name_matches] User.normalize_name(user.name) == User.normalize_name(params[:search][:name_matches])