From 4407b86bfe5bd96c69fde2036ab6a9e6e1fa8bc0 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 28 Oct 2024 16:57:35 +0000 Subject: [PATCH] FIX: Minimize database access following `db:migrate` The upgrade process was triggering the database migrations, and then calling `User.find()`. This is problematic because the `users` table may have been changed by the migrations, and accessing it with the 'old code' will raise an exception. This commit tweaks the Upgrader so that it loads the user object into memory **before** running database migrations. --- lib/docker_manager/upgrader.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/docker_manager/upgrader.rb b/lib/docker_manager/upgrader.rb index 186c052..f57040b 100644 --- a/lib/docker_manager/upgrader.rb +++ b/lib/docker_manager/upgrader.rb @@ -3,6 +3,7 @@ class DockerManager::Upgrader def initialize(user_id, repos, from_version) @user_id = user_id + @user = User.find(user_id) @repos = repos.is_a?(Array) ? repos : [repos] @from_version = from_version end @@ -258,7 +259,8 @@ def status(val) end def log_version_upgrade - StaffActionLogger.new(User.find(@user_id)).log_custom( + # Using cached user object to minimize database access after running migrations + StaffActionLogger.new(@user).log_custom( "discourse_update", from_version: @from_version, repository: @repos.map(&:path).join(", "),