-
Notifications
You must be signed in to change notification settings - Fork 562
use schema_cache #572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use schema_cache #572
Conversation
I ask because Lastly, WRT testing. That is SUPER SUPER easy now with Docker based SQL Server on Linux. I'll update the docs with how to do that and post back. |
|
First, Thank you for your fast reply and your great work on this gem! The inserts are normal model I can run the tests but they fail, I'll look into that. But I'm unsure how to write a test that tests the new implementation of |
|
Yup, I remember spending some time on this shortly after Rails v5 release. Tho I don't remember the numbers like this. I might have been looking elsewhere. Will work on this very soon. Test/Benchmark Diff--- a/lib/active_record/connection_adapters/sqlserver/schema_statements.rb
+++ b/lib/active_record/connection_adapters/sqlserver/schema_statements.rb
@@ -513,7 +514,11 @@ module ActiveRecord
end
def identity_columns(table_name)
- columns(table_name).select(&:is_identity?)
+ if $SCHEMCACHE
+ schema_cache.columns(table_name).select(&:is_identity?)
+ else
+ columns(table_name).select(&:is_identity?)
+ end
end
--- a/test/cases/scratchpad_test_sqlserver.rb
+++ b/test/cases/scratchpad_test_sqlserver.rb
@@ -1,9 +1,13 @@
require 'cases/helper_sqlserver'
+require 'models/book'
class ScratchpadTestSQLServer < ActiveRecord::TestCase
it 'helps debug things' do
- #
+ require 'benchmark'
+ puts Benchmark.realtime { 1000.times { |n| Book.create(name: n) } }
+ $SCHEMCACHE = true
+ puts Benchmark.realtime { 1000.times { |n| Book.create(name: n) } }
end
endTest/Benchmark Diff (output) |
|
Closing for #574 |
|
Very nice - thank you! :) |
|
@noelr This work in in master. I hope to release that branch to v5.0.5 within the week. Cheers! |
|
❤️ |
We had slow performance on inserts in rails 5 because
column_definitionsis called for each insert.The call to
column_definitionscomes fromquery_requires_identity_insert?which callsidentity_columnsNot sure what other consequences this patch has, please review. Also I'm unsure how to test.