- 05 5月, 2020 2 次提交
-
-
由 Ryuta Kamizono 提交于
```ruby steve = Person.find_by(name: "Steve") david = Author.find_by(name: "David") relation = Essay.where(writer: steve) # Before relation.rewhere(writer: david).to_a # => [] # After relation.rewhere(writer: david).to_a # => [david] ``` For now `rewhere` only works for truly column names, doesn't work for alias attributes, nested conditions, associations. To fix that, need to build new where clause first, and then get attribute names from new where clause.
-
由 akinomaeni 提交于
before ``` p Knot.create => #<Knot id: 1, created_at: "2016-05-05 01:29:47"> ``` after ``` p Knot.create => #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000"> ```
-
- 04 5月, 2020 1 次提交
-
-
由 Ryuta Kamizono 提交于
-
- 03 5月, 2020 4 次提交
-
-
由 Ryuta Kamizono 提交于
-
由 Ryuta Kamizono 提交于
-
由 Ryuta Kamizono 提交于
-
由 Eugene Kenny 提交于
Since 901d62c5, associations can only be autosaved once: after a record has been saved, `@new_record_before_save` will always be false. This assumes that records only transition to being persisted once, but there are two cases where it happens multiple times: when the transaction that saved the record is rolled back, and when the persisted record is later duplicated.
-
- 02 5月, 2020 4 次提交
-
-
由 Ryuta Kamizono 提交于
I supposed all aggregation functions will return numeric result in #39039, but that assumption was incorrect for `minimum` and `maximum`, if an aggregated column is non numeric type. I've restored type casting aggregated result for `minimum` and `maximum`. Fixes #39110.
-
由 Ryuta Kamizono 提交于
The type information for type casting is entirely separated to type object, so if anyone does passing a column to `type_cast` in Rails 6, they are likely doing something wrong. See the comment for more details: https://github.com/rails/rails/blob/28d815b89487ce4001a3f6f0ab684e6f9c017ed0/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb#L33-L42 This also deprecates passing legacy binds (an array of `[column, value]` which is 4.2 style format) to query methods on connection. That legacy format was kept for backward compatibility, instead of that, I've supported casted binds format (an array of casted values), it is easier to construct binds than existing two binds format.
-
由 Ryuta Kamizono 提交于
-
由 eileencodes 提交于
-
- 01 5月, 2020 5 次提交
-
-
由 Ryuta Kamizono 提交于
I've found the internal `without_transaction_enrollment` callbacks which have not been newly used over five years, when I tried to work reverting #9068 (https://github.com/rails/rails/pull/36049#issuecomment-487318060). I think that we will never make that callbacks public, since the mechanism of `without_transaction_enrollment` is too implementation specific, at least before #9068, records in a transaction had enrolled all into the transaction. That callbacks was introduced at #18936 to make `touch_later` #19324, but I think that the internal callbacks is overkill to just make the `touch_later` only, and invoking the extra callbacks also have a little overhead even if we haven't used that. So I think we can remove the internal callbacks for now, until we will come up with a good use for that callbacks.
-
由 Jean Boussier 提交于
-
由 Ryuta Kamizono 提交于
`column_types` is empty except PostgreSQL adapter, and `attribute_types.each_key { |k| column_types.delete k }` is also empty even if PostgreSQL adapter almost all case, so that code is quite useless. This improves performance for `find_by_sql` to avoid that useless loop as much as possible. ```ruby ActiveRecord::Schema.define do create_table :active_storage_blobs do |t| t.string :key, null: false t.string :filename, null: false t.string :content_type t.text :metadata t.string :service_name, null: false t.bigint :byte_size, null: false t.string :checksum, null: false t.datetime :created_at, null: false t.index [ :key ], unique: true end end class ActiveStorageBlob < ActiveRecord::Base end Benchmark.ips do |x| x.report("find_by") { ActiveStorageBlob.find_by(id: 1) } end ``` Before: ``` Warming up -------------------------------------- find_by 1.256k i/100ms Calculating ------------------------------------- find_by 12.595k (± 3.4%) i/s - 64.056k in 5.091599s ``` After: ``` Warming up -------------------------------------- find_by 1.341k i/100ms Calculating ------------------------------------- find_by 13.170k (± 3.5%) i/s - 67.050k in 5.097439s ``` To avoid column types loop for PostgreSQL adapter, this skips returning additional column types if a column has already been type casted by pg decoders. Fortunately this fixes #36186 partly for common types.
-
由 Ryuta Kamizono 提交于
-
由 Ryuta Kamizono 提交于
Relying on the `Arel::Table.engine` is convenient if an app have only a single kind of database, but if not so, the global state is not always the same with the current connection.
-
- 30 4月, 2020 1 次提交
-
-
由 Ryuta Kamizono 提交于
`allowed_index_name_length` was used for internal temporary operations in SQLite3, since index name in SQLite3 must be globally unique and SQLite3 doesn't have ALTER TABLE feature (so it is emulated by creating temporary table with prefix). `allowed_index_name_length` was to reserve the margin for the prefix, but actually SQLite3 doesn't have a limitation for identifier name length, so the margin has removed at 36901e6e. Now `allowed_index_name_length` is no longer relied on by any adapter, so I'd like to remove the internal specific method which is no longer used.
-
- 29 4月, 2020 3 次提交
-
-
由 Ryuta Kamizono 提交于
Related #39039. Currently PostgreSQL adapter is the only adapter that rely on type casting by `result.column_types`, now the adapter can return numeric value without type casting by Active Record side. So we can remove that useless type cast on aggregated value.
-
由 Ryuta Kamizono 提交于
Actually SQLite3 doesn't have a limitation for identifier name length, so do not need `- 2` margin internally to perform temporary rename operations.
-
由 Ryuta Kamizono 提交于
This is a smaller alternative of performance improvement, without refactoring type casting mechanism #39009. This is relatively a smaller change (but about 40% faster than before), so I think this could be easier reviewed without discuss about refactoring type casting mechanism. This just makes `attribute.in(values)` less allocation from an array of casted nodes to one casted array node. ```ruby ids = (1..1000).each.map do |n| Post.create!.id end Benchmark.ips do |x| x.report("where with ids") do Post.where(id: ids).to_a end x.report("where with sanitize") do Post.where(ActiveRecord::Base.sanitize_sql(["id IN (?)", ids])).to_a end x.compare! end ``` Before: ``` Warming up -------------------------------------- where with ids 7.000 i/100ms where with sanitize 13.000 i/100ms Calculating ------------------------------------- where with ids 70.661 (± 5.7%) i/s - 357.000 in 5.072771s where with sanitize 130.993 (± 7.6%) i/s - 663.000 in 5.096085s Comparison: where with sanitize: 131.0 i/s where with ids: 70.7 i/s - 1.85x slower ``` After: ``` Warming up -------------------------------------- where with ids 10.000 i/100ms where with sanitize 13.000 i/100ms Calculating ------------------------------------- where with ids 98.174 (± 7.1%) i/s - 490.000 in 5.012851s where with sanitize 132.289 (± 8.3%) i/s - 663.000 in 5.052728s Comparison: where with sanitize: 132.3 i/s where with ids: 98.2 i/s - 1.35x slower ```
-
- 28 4月, 2020 2 次提交
-
-
由 Ryuta Kamizono 提交于
```ruby class Post < ActiveRecord::Base end posts = Post.where(id: 1, title: "foo") Benchmark.ips do |x| x.report("scope_for_create") { posts.scope_for_create } end ``` Before: ``` Warming up -------------------------------------- scope_for_create 30.125k i/100ms Calculating ------------------------------------- scope_for_create 334.033k (± 4.4%) i/s - 1.687M in 5.060493s ``` After: ``` Warming up -------------------------------------- scope_for_create 35.088k i/100ms Calculating ------------------------------------- scope_for_create 388.603k (±11.8%) i/s - 1.930M in 5.080998s ```
-
由 Ryuta Kamizono 提交于
Define `value_for_database` and `value_before_type_cast` methods, and use those.
-
- 27 4月, 2020 2 次提交
-
-
由 Ryuta Kamizono 提交于
This is required for #39063 to use `PG::TextDecoder::Numeric`. Ref https://github.com/ged/ruby-pg/pull/25. The pg gem 1.1.0 was released at August 24, 2018, so I think it is good timing to bump the required version for improving and cleaning up the code base. https://rubygems.org/gems/pg/versions
-
由 Ryuta Kamizono 提交于
`in_clause_length` was added at c5a284f8 to address to Oracle IN clause length limitation. Now `in_clause_length` is entirely integrated in Arel visitor since #35838 and #36074. Since Oracle visitors are the only code that rely on `in_clause_length`. so I'd like to remove that from Rails code base, like has removed Oracle visitors (#38946).
-
- 26 4月, 2020 1 次提交
-
-
由 Ryuta Kamizono 提交于
Before this, 1000 `Or` nodes will raise "stack level too deep" due to visiting too deep Arel ast. This makes more concise Arel `Or` ast and `Or` visitor non recursive if `Or` nodes are adjoined, as a result, "stack level too deep" is no longer raised. ```ruby class Post < ActiveRecord::Base end posts = (0..500).map { |i| Post.where(id: i) } Benchmark.ips do |x| x.report("inject scopes") { posts.inject(&:or).to_sql } end ``` Before: ``` Warming up -------------------------------------- where with ids 9.000 i/100ms Calculating ------------------------------------- where with ids 96.126 (± 2.1%) i/s - 486.000 in 5.058960s ``` After: ``` Warming up -------------------------------------- inject scopes 10.000 i/100ms Calculating ------------------------------------- inject scopes 101.714 (± 2.9%) i/s - 510.000 in 5.018880s ``` Fixes #39032.
-
- 25 4月, 2020 3 次提交
-
-
由 Ryuta Kamizono 提交于
If only one Arel node exist, wrapping a node by `And` node is obviously redundant, make concise Arel ast will improve performance for visiting the ast (about 20% faster for complex ast case). ```ruby class Post < ActiveRecord::Base end posts = (0..500).map { |i| Post.where(id: i) } Benchmark.ips do |x| x.report("inject scopes") { posts.inject { |res, scope| res.or(scope) }.to_sql } end ``` Before: ``` Warming up -------------------------------------- where with ids 8.000 i/100ms Calculating ------------------------------------- where with ids 80.416 (± 2.5%) i/s - 408.000 in 5.078118s ``` After: ``` Warming up -------------------------------------- where with ids 9.000 i/100ms Calculating ------------------------------------- where with ids 96.126 (± 2.1%) i/s - 486.000 in 5.058960s ```
-
由 Ryuta Kamizono 提交于
Currently, `count` and `average` always returns numeric value, but `sum`, `maximum`, and `minimum` not always return numeric value if aggregated on custom attribute type. I think that inconsistent behavior is surprising: ```ruby # All adapters except postgresql adapter are affected # by custom type casting. Book.group(:status).sum(:status) # => { "proposed" => "proposed", "published" => nil } ``` That is caused by fallback looking up cast type to `type_for(column)`. Now all supported adapters can return numeric value without that fallback, so I think we can remove that, it will also fix aggregate functions to return numeric value consistently.
-
由 Ryuta Kamizono 提交于
This allows to work `author.books.insert_all` as expected. Co-authored-by: NJosef Šimánek <josef.simanek@gmail.com>
-
- 23 4月, 2020 4 次提交
-
-
由 Andrey Koleshko 提交于
-
由 Ryuta Kamizono 提交于
There is no worth to keep those unused aliases and tests which are private API.
-
由 Flavio Wuensche 提交于
reload column_names after ignored_columns assignment code review: remove unnecessary setup and move up reload_schema_from_cache
-
由 Godfrey Chan 提交于
I wrote this shell script to find words from the Rails repo, so I can paste them into https://www.horsepaste.com/ for the [codenames game](https://en.m.wikipedia.org/wiki/Codenames_(board_game)). ```bash git grep -Il '' | \ grep -v -E "CHANGELOG|Gemfile|gemspec|package\.json|yarn\.lock" | \ xargs cat | \ sed '/[^ ]\{10,\}/d' | \ sed 's/\([A-Z]\)/ \1/g' | \ tr 'A-Z' 'a-z' | \ tr -c -s 'a-z' '\n' | \ sed '/^.\{0,3\}$/d' | \ sort | \ uniq | \ tr '\n' ',' | \ pbcopy ``` You can see the result in https://www.horsepaste.com/rails-fixed. Click "Next game" to cycle the words. Found some typos in the codebase from this
😂 This is how I generated the list of possible typos: ```bash git grep -Il '' | \ grep -v -E "CHANGELOG|Gemfile|gemspec|package\.json|yarn\.lock" | \ xargs cat | \ sed '/[^ ]\{10,\}/d' | \ sed 's/\([A-Z]\)/ \1/g' | \ tr 'A-Z' 'a-z' | \ tr -c -s 'a-z' '\n' | \ sed '/^.\{0,3\}$/d' | \ sort | \ uniq | \ aspell --ignore-case list ``` I manually reviewed the list and made the corrections in this commit. The rest on the list are either: * Bugs in my script: it split things like "doesn't" into "doesn" and "t", if find things like `#ffffff` and extracts "ffffff" as a word, etc * British spelling: honour, optimised * Foreign words: bonjour, espanol * Names: nginx, hanekawa * Technical words: mutex, xhtml * Portmanteau words: autosave, nodelist * Invented words: camelize, coachee * Shortened words: attrs, repo * Deliberate typos: hllo, hillo (used in code examples, etc) * Lorem ipsum words: arcu, euismod This is the [output](https://gist.github.com/chancancode/eb0b573d667dc31906f33f1fb0b22313) of the script *after* fixing the typos included in this commit. In theory, someone can run that command again in the future and compare the output to catch new typos (i.e. using my list to filter out known typos). Limitations: the aspell dictionary could be wrong, I could have miss things, and my script ignores words that are less than 3 characters or longer than 10 characters.
-
- 20 4月, 2020 2 次提交
-
-
由 Islam Taha 提交于
Update activerecord changelog Specify DB name in changelog and fix typo
-
由 Eugene Kenny 提交于
While not a particularly good idea, it's possible to use `object_id` as an attribute name, typically by defining a polymorphic association named `object`. Since 718a32ca, transactional callbacks deduplicate records by their `object_id`, but this causes incorrect behaviour when the record has an attribute with that name. Using `__id__` instead makes a naming collision much less likely.
-
- 18 4月, 2020 1 次提交
-
-
由 Nimish 提交于
-
- 17 4月, 2020 2 次提交
-
-
由 Ryuta Kamizono 提交于
Follow up to 404e1a0a.
-
由 Nick Burns 提交于
Co-Authored-By: NEileen M. Uchitelle <eileencodes@users.noreply.github.com>
-
- 16 4月, 2020 1 次提交
-
-
由 eileencodes 提交于
This PR allows for passing `if_exists` options to the `remove_index` method so that we can ignore already removed indexes. This work follows column `if/if_not_exists` from #38352 and `:if_not_exists` on `add_index` from #38555. We've found this useful at GitHub, there are migrations where we don't want to raise if an index was already removed. This will allow us to remove a monkey patch on `remove_index`. I considered raising after the `index_name_for_remove` method is called but that method will raise if the index doesn't exist before we get to execute. I have a commit that refactors this but after much consideration this change is cleaner and more straightforward than other ways of implementing this. This change also adds a little extra validation to the `add_index` test. Fix `nodoc` on edited methods.
-
- 15 4月, 2020 2 次提交
-
-
由 Ryuta Kamizono 提交于
#29589 changed merging scope order to allow to unscope default scopes on association scope (#29611), but that caused a regression #38811 that accidentally allow join constraint which is required. ``` % bin/test test/cases/associations/has_many_associations_test.rb -n test_unscopes_the_default_scope_of_associated_model_when_used_with_include Run options: -n test_unscopes_the_default_scope_of_associated_model_when_used_with_include --seed 32978 # Running: E Error: HasManyAssociationsTest#test_unscopes_the_default_scope_of_associated_model_when_used_with_include: NoMethodError: undefined method `children' for nil:NilClass ~/rails/activerecord/lib/active_record/associations/join_dependency/join_association.rb:39:in `block in join_constraints' ~/rails/activerecord/lib/active_record/associations/join_dependency/join_association.rb:30:in `reverse_each' ~/rails/activerecord/lib/active_record/associations/join_dependency/join_association.rb:30:in `with_index' ~/rails/activerecord/lib/active_record/associations/join_dependency/join_association.rb:30:in `join_constraints' ~/rails/activerecord/lib/active_record/associations/join_dependency.rb:171:in `make_constraints' ~/rails/activerecord/lib/active_record/associations/join_dependency.rb:196:in `block in walk' ~/rails/activerecord/lib/active_record/associations/join_dependency.rb:196:in `each' ~/rails/activerecord/lib/active_record/associations/join_dependency.rb:196:in `flat_map' ~/rails/activerecord/lib/active_record/associations/join_dependency.rb:196:in `walk' ~/rails/activerecord/lib/active_record/associations/join_dependency.rb:90:in `block in join_constraints' ~/rails/activerecord/lib/active_record/associations/join_dependency.rb:87:in `each' ~/rails/activerecord/lib/active_record/associations/join_dependency.rb:87:in `flat_map' ~/rails/activerecord/lib/active_record/associations/join_dependency.rb:87:in `join_constraints' ~/rails/activerecord/lib/active_record/relation/query_methods.rb:1226:in `build_join_query' ~/rails/activerecord/lib/active_record/relation/query_methods.rb:1211:in `build_joins' ~/rails/activerecord/lib/active_record/relation/query_methods.rb:1091:in `build_arel' ~/rails/activerecord/lib/active_record/relation/query_methods.rb:1063:in `arel' ~/rails/activerecord/lib/active_record/relation/finder_methods.rb:419:in `block in limited_ids_for' ~/rails/activerecord/lib/active_record/relation.rb:867:in `skip_query_cache_if_necessary' ~/rails/activerecord/lib/active_record/relation/finder_methods.rb:419:in `limited_ids_for' ~/rails/activerecord/lib/active_record/relation/finder_methods.rb:398:in `apply_join_dependency' ~/rails/activerecord/lib/active_record/relation.rb:839:in `block in exec_queries' ~/rails/activerecord/lib/active_record/relation.rb:867:in `skip_query_cache_if_necessary' ~/rails/activerecord/lib/active_record/relation.rb:834:in `exec_queries' ~/rails/activerecord/lib/active_record/relation.rb:639:in `load' ~/rails/activerecord/lib/active_record/relation.rb:250:in `records' ~/rails/activerecord/lib/active_record/relation/finder_methods.rb:508:in `find_take' ~/rails/activerecord/lib/active_record/relation/finder_methods.rb:98:in `take' ~/rails/activerecord/lib/active_record/relation/finder_methods.rb:458:in `find_one' ~/rails/activerecord/lib/active_record/relation/finder_methods.rb:442:in `find_with_ids' ~/rails/activerecord/lib/active_record/relation/finder_methods.rb:69:in `find' ~/rails/activerecord/test/cases/associations/has_many_associations_test.rb:2689:in `block in <class:HasManyAssociationsTest>' bin/test test/cases/associations/has_many_associations_test.rb:2683 ``` Required join constraint should not be allowed to unscoping. Fixes #38811.
-
由 Ryuta Kamizono 提交于
This removes ibm_db, informix, mssql, oracle, and oracle12 Arel visitors which are not used in the code base. Actually oracle and oracle12 visitors are used at oracle-enhanced adapter, but now I think that those visitors should be in the adapter's repo like sqlserver adapter and the dedicated Arel visitor (https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/master/lib/arel/visitors/sqlserver.rb), otherwise it is hard to find a bug and review PRs for the oracle visitors (e.g. #35838, #37646), since we don't have knowledge and environment enough for Oracle.
-