mirror of
https://github.com/discourse/discourse.git
synced 2024-12-05 09:36:19 +08:00
28292d2759
Previously we had many places in the app that called `hostname` to get hostname of a server. This commit replaces the pattern in 2 ways 1. We cache the result in `Discourse.os_hostname` so it is only ever called once 2. We prefer to use Socket.gethostname which avoids making a shell command This improves performance as we are not spawning hostname processes throughout the app lifetime
57 lines
1.1 KiB
Ruby
57 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module FreedomPatches
|
|
module SchemaMigrationDetails
|
|
def exec_migration(conn, direction)
|
|
rval = nil
|
|
|
|
time = Benchmark.measure do
|
|
rval = super
|
|
end
|
|
|
|
sql = <<SQL
|
|
INSERT INTO schema_migration_details(
|
|
version,
|
|
hostname,
|
|
name,
|
|
git_version,
|
|
duration,
|
|
direction,
|
|
rails_version,
|
|
created_at
|
|
) values (
|
|
:version,
|
|
:hostname,
|
|
:name,
|
|
:git_version,
|
|
:duration,
|
|
:direction,
|
|
:rails_version,
|
|
:created_at
|
|
)
|
|
SQL
|
|
|
|
hostname = Discourse.os_hostname
|
|
sql = ActiveRecord::Base.public_send(:sanitize_sql_array, [sql, {
|
|
version: version || "",
|
|
duration: (time.real * 1000).to_i,
|
|
hostname: hostname,
|
|
name: name,
|
|
git_version: Discourse.git_version,
|
|
created_at: Time.zone.now,
|
|
direction: direction.to_s,
|
|
rails_version: Rails.version
|
|
}])
|
|
|
|
conn.execute(sql)
|
|
|
|
rval
|
|
end
|
|
|
|
end
|
|
end
|
|
|
|
class ActiveRecord::Migration
|
|
prepend FreedomPatches::SchemaMigrationDetails
|
|
end
|