FIX: Minimize database access following `db:migrate` (#247)

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.
This commit is contained in:
David Taylor 2024-10-28 17:14:47 +00:00 committed by GitHub
parent d2d02c6fea
commit 540a0640a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 1 deletions

View File

@ -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 @@ class DockerManager::Upgrader
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(", "),