Fix randomly occuring 0 durations
Withing the new VSA backend we use the durations returned from PG directly.
Example:
10.times { puts ActiveRecord::Base.connection.execute(Issue.limit(1).select('(updated_at - created_at) as duration').to_sql).to_a.inspect }
For some reason (could be config differences on the replicas), running the query above returns different values:
[{"duration"=>"P1DT3H11M5.866237S"}]
[{"duration"=>"P1DT3H11M5.866237S"}]
[{"duration"=>"P1DT3H11M5.866237S"}]
[{"duration"=>"P1DT3H11M5.866237S"}]
[{"duration"=>"1 day 03:11:05.866237"}]
[{"duration"=>"1 day 03:11:05.866237"}]
[{"duration"=>"P1DT3H11M5.866237S"}]
[{"duration"=>"P1DT3H11M5.866237S"}]
[{"duration"=>"P1DT3H11M5.866237S"}]
[{"duration"=>"P1DT3H11M5.866237S"}]
ActiveSupport::Duration
cannot parse "1 day 03:11:05.866237
" hence the duration will be nil. Later we cast the value to float and it becomes 0.
The fix is to do the same thing that we do in the old VSA backend: use EXTRACT(epoch from ...)
so the DB returns seconds.
Edited by Adam Hegyi