Skip to content

Commit f5eee69

Browse files
committed
Memoize #version_year
1 parent ddb3ac7 commit f5eee69

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,14 @@ def initialize_dateformatter
435435
end
436436

437437
def version_year
438-
vstring = _raw_select('SELECT @@version', fetch: :rows).first.first.to_s
439-
return 2016 if vstring =~ /vNext/
440-
/SQL Server (\d+)/.match(vstring).to_a.last.to_s.to_i
441-
rescue Exception => e
442-
2016
438+
return @version_year if defined?(@version_year)
439+
@version_year = begin
440+
vstring = _raw_select('SELECT @@version', fetch: :rows).first.first.to_s
441+
return 2016 if vstring =~ /vNext/
442+
/SQL Server (\d+)/.match(vstring).to_a.last.to_s.to_i
443+
rescue Exception => e
444+
2016
445+
end
443446
end
444447

445448
end

0 commit comments

Comments
 (0)