Skip to content

Commit

Permalink
FIX: Minimize database access following db:migrate
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davidtaylorhq committed Oct 28, 2024
1 parent d2d02c6 commit 4407b86
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/docker_manager/upgrader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(", "),
Expand Down

0 comments on commit 4407b86

Please sign in to comment.