mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
DEV: Refactor migrations-tooling
* Updates GitHub Action for migrations * Rubocop: Always `EnforcedShorthandSyntax` for hashes in the `migrations` directory * Automatically load all available converter steps * Enable YJIT at runtime, if available * Progressbar shows skipped records and other small improvements
This commit is contained in:

committed by
Gerhard Schlager

parent
7b5839ec44
commit
71a90dcba2
@ -2,21 +2,16 @@
|
||||
|
||||
module Migrations
|
||||
module DateHelper
|
||||
# based on code from https://gist.github.com/emmahsax/af285a4b71d8506a1625a3e591dc993b
|
||||
def self.human_readable_time(secs)
|
||||
return "< 1 second" if secs < 1
|
||||
def self.human_readable_time(seconds)
|
||||
hours, remainder = seconds.divmod(3600)
|
||||
minutes, seconds = remainder.divmod(60)
|
||||
format("%02d:%02d:%02d", hours, minutes, seconds)
|
||||
end
|
||||
|
||||
[[60, :seconds], [60, :minutes], [24, :hours], [Float::INFINITY, :days]].map do |count, name|
|
||||
next if secs <= 0
|
||||
|
||||
secs, number = secs.divmod(count)
|
||||
unless number.to_i == 0
|
||||
"#{number.to_i} #{number == 1 ? name.to_s.delete_suffix("s") : name}"
|
||||
end
|
||||
end
|
||||
.compact
|
||||
.reverse
|
||||
.join(", ")
|
||||
def self.track_time
|
||||
start_time = Time.now
|
||||
yield
|
||||
Time.now - start_time
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user