-
Notifications
You must be signed in to change notification settings - Fork 18
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
[prepared statements] fix for auto_encode_arrays, refactoring #59
Conversation
201d373
to
c36178c
Compare
49dc09b
to
06775fe
Compare
06775fe
to
36635d7
Compare
when true then "true" | ||
when false then "false" | ||
when nil then "NULL" | ||
when EMPTY_ARRAY then array_encoder ? "'{}'" : "NULL" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arr = []
freeze_arr = [].freeze
Benchmark.ips do |x|
x.report("new") {
case arr
when [] then true
else false
end
}
x.report("inline freeze") {
case arr
when [].freeze then true
else false
end
}
x.report("var freeze") {
case arr
when freeze_arr then true
else false
end
}
x.compare!
end;
# Comparison:
# var freeze: 6412829.6 i/s
# new: 5822569.7 i/s - 1.10x slower
# inline freeze: 5379263.0 i/s - 1.19x slower
@@ -30,8 +26,9 @@ def deserializer_cache | |||
|
|||
private def run(sql, params) | |||
prepared_sql, binds, _bind_names = @param_binder.bind(sql, *params) | |||
@prepared_cache ||= PreparedCache.new(unprepared) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lazy evaluate
@@ -28,6 +28,10 @@ def prepare_statement(sql) | |||
|
|||
private | |||
|
|||
def raw_connection | |||
@connection.raw_connection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for usage with ActiveRecord
@SamSaffron PR ready to review |
6b2f1d4
to
bc2598c
Compare
bc2598c
to
35e3eb6
Compare
class MiniSql::Postgres::TestAutoEncodeArraysPrepared < MiniSql::Postgres::TestPreparedConnection | ||
include MiniSql::Postgres::ArrayTests | ||
|
||
def setup | ||
@unprepared_connection = pg_connection(auto_encode_arrays: true) | ||
@connection = @unprepared_connection.prepared | ||
|
||
setup_tables | ||
end | ||
end | ||
|
||
class MiniSql::Postgres::TestAutoEncodeArraysUnprepared < MiniSql::Postgres::TestConnection | ||
include MiniSql::Postgres::ArrayTests | ||
|
||
def setup | ||
@connection = pg_connection(auto_encode_arrays: true) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run all test for connection with auto_encode_arrays: true
@@ -61,12 +61,8 @@ def type_map | |||
@type_map ||= self.class.type_map(raw_connection) | |||
end | |||
|
|||
def prepared(condition = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a real application the parameter condition
was never used
Hi @SamSaffron, I remind you about this PR, because the master branch does not work correctly in some situations in mode |
no worries, thanks the ruby-head failure is a bit of a nightmare, bigdecimal is a dependency on Ruby 3.4 and up. |
auto_encode_arrays
(prepared, unprepared)prepared
method)ActiveRecord