aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/delegation.rb
Commit message (Collapse)AuthorAgeFilesLines
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Deprecate delegating to `arel` in `Relation`Ryuta Kamizono2017-06-291-0/+2
| | | | | | | | | | | | | Active Record doesn't rely delegating to `arel` in the internal since 425f2ca. The delegation is a lower priority than delegating to `klass`, so it is pretty unclear which method is delegated to `arel`. For example, `bind_values` method was removed at b06f64c (a series of changes https://github.com/rails/rails/compare/79f71d3...b06f64c). But a relation still could respond to the method because `arel` also have the same named method (#28976). Removing the delegation will achieve predictable behavior.
* Merge pull request #28932 from ↵Rafael França2017-06-281-10/+0
|\ | | | | | | | | kamipo/remove_method_missing_in_relation_delegation Remove `method_missing` in `Relation::Delegation`
| * Remove `method_missing` in `Relation::Delegation`Ryuta Kamizono2017-04-301-10/+0
| | | | | | | | The `method_missing` is never reached since 64c53d7c.
* | Remove delegating to arel in a relationRyuta Kamizono2017-06-291-2/+0
| | | | | | | | | | The delegation was needed since passing `relation` with `relation.bound_attributes`. It should use `relation.arel` in that case.
* | Merge pull request #29098 from kamipo/fix_association_with_extension_issuesMatthew Draper2017-05-301-2/+0
|\ \ | | | | | | | | | Fix association with extension issues
| * | Fix association with extension issuesRyuta Kamizono2017-05-281-2/+0
| |/ | | | | | | | | | | | | | | This fixes the following issues. * `association_scope` doesn't include `default_scope`. Should use `scope` instead. * We can't use `method_missing` for customizing existing method. * We can't use `relation_delegate_class` for sharing extensions. Should extend per association.
* / Delegate `ast` and `locked` to `arel` explicitlyRyuta Kamizono2017-05-061-0/+2
|/ | | | | | | | Currently `ast` and `locked` are used in the internal but delegating to `arel` is depend on `method_missing`. If a model class is defined these methods, `select_all` will be broken. It should be delegated to `arel` explicitly.
* Merge pull request #28828 from kamipo/fix_extending_modules_on_associationRafael França2017-04-251-0/+2
|\ | | | | Mixin `CollectionProxy::DelegateExtending` after `ClassSpecificRelation`
| * Mixin `CollectionProxy::DelegateExtending` after `ClassSpecificRelation`Ryuta Kamizono2017-04-221-0/+2
| | | | | | | | | | | | | | | | | | | | `ClassSpecificRelation` has `method_missing` and the `method_missing` is called first. if an associated class has the missing method in a relation, never reach to the `method_missing` in the `CollectionProxy`. I extracted `DelegateExtending` and included it to the delegate class that including `ClassSpecificRelation` to fix the issue. Fixes https://github.com/rails/rails/pull/28246#issuecomment-296033784.
* | `respond_to_missing?` should be privateRyuta Kamizono2017-04-221-5/+3
|/ | | | | | | Follow up of 03d3f036. Some of `respond_to?` were replaced to `respond_to_missing?` in 03d3f036. But the visibility is still public. It should be private.
* Use `load` rather than `collect` for force loadingRyuta Kamizono2017-03-191-1/+1
| | | | | | | Since b644964b `ActiveRecord::Relation` includes `Enumerable` so delegating `collect`, `all?`, and `include?` are also unneeded. `collect` without block returns `Enumerable` without preloading by that. We should use `load` rather than `collect` for force loading.
* Delegate `uniq` to `records`Ryuta Kamizono2017-03-181-1/+1
| | | | | | | | | | This fixes CI failure due to 48f3be8c. `Enumerable#uniq` was introduced since Ruby 2.4. We should delegate `uniq` to `records` explicitly. And since b644964b `ActiveRecord::Relation` includes `Enumerable` so delegating `map` is unneeded.
* Simply delegate `as_json` to `records`Ryuta Kamizono2017-03-101-1/+1
|
* Delegate `to_sentence` and `to_fomatted_s` to `records`kenta-s2017-02-041-0/+1
|
* Privatize unneededly protected methods in Active RecordAkira Matsuda2017-01-051-1/+1
|
* Mark internal cache constants as privateMatthew Draper2016-12-311-1/+4
| | | | Closes #14640
* Privatize unneededly protected methods in Active RecordAkira Matsuda2016-12-241-1/+1
|
* removes requires already present in active_support/railsXavier Noria2016-10-271-2/+0
|
* let Regexp#match? be globally availableXavier Noria2016-10-271-1/+0
| | | | | | Regexp#match? should be considered to be part of the Ruby core library. We are emulating it for < 2.4, but not having to require the extension is part of the illusion of the emulation.
* Override `respond_to_missing?` instead of `respond_to?` when possibleSean Griffin2016-08-311-1/+1
| | | | | | | | | | This was almost every case where we are overriding `respond_to?` in a way that mirrors a parallel implementation of `method_missing`. There is one remaining case in Active Model that should probably do the same thing, but had a sufficiently strange implementation that I want to investigate it separately. Fixes #26333.
* Merge pull request #26012 from grosser/grosser/missingSean Griffin2016-08-141-1/+1
|\ | | | | add more array methods to straight delegation to speed up calling them
| * add index to array methods so we can call it on relationsMichael Grosser2016-08-121-1/+1
| |
* | normalizes indentation and whitespace across the projectXavier Noria2016-08-061-21/+21
| |
* | modernizes hash syntax in activerecordXavier Noria2016-08-061-2/+2
| |
* | applies new string literal convention in activerecord/libXavier Noria2016-08-061-3/+3
|/ | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* adds missing requiresXavier Noria2016-07-241-0/+1
|
* systematic revision of =~ usage in ARXavier Noria2016-07-231-1/+1
| | | | | Where appropriatei, prefer the more concise Regexp#match?, String#include?, String#start_with?, or String#end_with?
* delegate encode_with instead of to_yaml, which is deprecatedVipul A M2016-05-051-1/+1
|
* connection adapters column, delegation in Active Record have not use of ↵Gaurav Sharma2016-03-311-1/+0
| | | | | ‘set’ found these commits https://github.com/rails/rails/commit/9cc8c6f3730df3d94c81a55be9ee1b7b4ffd29f6, https://github.com/rails/rails/commit/9d79334a1dee67e31222c790e231772deafcaeb8 that also should remove it.
* Mutating the result of Relation#to_a should not affect the relationMatthew Draper2016-02-211-1/+1
| | | | | | Clarifying this separation and enforcing relation immutability is the culmination of the previous efforts to remove the mutator method delegations.
* Add methods to array delegation from `Relation`Kevin Dougherty2016-02-191-1/+2
| | | | | | | | | | Delegation of some `Array` methods was removed in commit 9d79334. That change did add explicit delegation of a few methods that `Array` has but which aren't on `Enumerable`. However, a few non-mutation methods were omitted. This adds `Array` delegation of `#in_groups`, `#in_groups_of`, `#shuffle` and `#split`. This allows things like `MyThing.all.in_groups_of(3) { ... }` to continue working as they did before commit 9d79334.
* Ensure `Relation` responds to `shuffle`Sean Griffin2015-12-011-1/+1
| | | | | It appears that I missed this one when I delegated all the non-mutation array methods that were not on Enumerable
* Remove blanket array delegation from `Relation`Sean Griffin2015-11-231-14/+2
| | | | | | | | | As was pointed out by #17128, our blacklist of mutation methods was non-exhaustive (and would need to be kept up to date with each new version of Ruby). Now that `Relation` includes `Enumerable`, the number of methods that we actually need to delegate are pretty small. As such, we can change to explicitly delegating the few non-mutation related methods that `Array` has which aren't on `Enumerable`
* docs, nodoc internal Active Record `DelegateCache`. [ci skip]Yves Senn2015-10-131-3/+3
|
* Freeze string literals when not mutated.schneems2015-07-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I wrote a utility that helps find areas where you could optimize your program using a frozen string instead of a string literal, it's called [let_it_go](https://github.com/schneems/let_it_go). After going through the output and adding `.freeze` I was able to eliminate the creation of 1,114 string objects on EVERY request to [codetriage](codetriage.com). How does this impact execution? To look at memory: ```ruby require 'get_process_mem' mem = GetProcessMem.new GC.start GC.disable 1_114.times { " " } before = mem.mb after = mem.mb GC.enable puts "Diff: #{after - before} mb" ``` Creating 1,114 string objects results in `Diff: 0.03125 mb` of RAM allocated on every request. Or 1mb every 32 requests. To look at raw speed: ```ruby require 'benchmark/ips' number_of_objects_reduced = 1_114 Benchmark.ips do |x| x.report("freeze") { number_of_objects_reduced.times { " ".freeze } } x.report("no-freeze") { number_of_objects_reduced.times { " " } } end ``` We get the results ``` Calculating ------------------------------------- freeze 1.428k i/100ms no-freeze 609.000 i/100ms ------------------------------------------------- freeze 14.363k (± 8.5%) i/s - 71.400k no-freeze 6.084k (± 8.1%) i/s - 30.450k ``` Now we can do some maths: ```ruby ips = 6_226k # iterations / 1 second call_time_before = 1.0 / ips # seconds per iteration ips = 15_254 # iterations / 1 second call_time_after = 1.0 / ips # seconds per iteration diff = call_time_before - call_time_after number_of_objects_reduced * diff * 100 # => 0.4530373333993266 miliseconds saved per request ``` So we're shaving off 1 second of execution time for every 220 requests. Is this going to be an insane speed boost to any Rails app: nope. Should we merge it: yep. p.s. If you know of a method call that doesn't modify a string input such as [String#gsub](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37) please [give me a pull request to the appropriate file](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37), or open an issue in LetItGo so we can track and freeze more strings. Keep those strings Frozen ![](https://www.dropbox.com/s/z4dj9fdsv213r4v/let-it-go.gif?dl=1)
* Allow Relation#compact using delegationJordan Raine2015-05-281-1/+1
|
* Remove unneeded `require 'as/deprecation'`claudiob2015-01-041-1/+0
| | | | | Tests should still pass after removing `require 'active_support/deprecation'` from these files since the related deprecations have been removed.
* Put back Relation#join method as a delegate to ArrayBogdan Gusiev2014-05-051-1/+1
| | | | | | | | This is a regression 4.0 -> 4.1 fix. In 4.1.0 Relation#join is delegated to Arel#SelectManager. In 4.0 series it is delegated to Array#join This patch puts back the behaviour of 4.0
* select! renamed to avoid name collision Array#select!Earl J St Sauver2014-04-211-1/+1
| | | | | | | | Fixes #14752 Select mimics the block interface of arrays, but does not mock the block interface for select!. This change moves the api to be a private method, _select!.
* Create a blacklist to disallow mutator methods to be delegated to `Array`.Lauro Caetano2013-12-171-11/+14
| | | | | | | | This change was necessary because the whitelist wouldn't work. It would be painful for users trying to update their applications. This blacklist intent to prevent odd bugs and confusion in code that call mutator methods directely on the `Relation`.
* argument prefix warning removedArun Agrawal2013-12-131-1/+1
| | | | * interpreted as a argument prefix
* Add a bunch of Relation -> Array delegate methods to the whitelist. This ↵Jeremy Kemper2013-12-121-4/+12
| | | | won't last - aim to switch back to a blacklist for mutator methods.
* Use `public_send` instead of just use `send`.Lauro Caetano2013-12-121-5/+5
|
* Use a whitelist to delegate methods to arrayLauro Caetano2013-12-121-18/+6
|
* Deprecate the delegation of Array bang methods in ActiveRecord::DelegationBen Woosley2013-09-041-3/+14
| | | | | | | | | | | The primary means of returning results for Array bang methods is to modify the array in-place. When you call these methods on a relation, that array is created, modified, and then thrown away. Only the secondary return value is exposed to the caller. Removing this delegation is a straight-forward way to reduce user error by forcing callers to first explicitly call #to_a in order to expose the array to be acted on by the bang method.
* no need to fully qualifyAaron Patterson2013-08-301-1/+1
|
* move the cache to the AR models and populate it on inheritedAaron Patterson2013-08-301-20/+29
|
* no need for the const_get since we lockAaron Patterson2013-08-301-5/+1
|
* require a class for cache computationsAaron Patterson2013-08-301-1/+3
|