aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
Commit message (Collapse)AuthorAgeFilesLines
* Do not cache prepared statements that are unlikely to have cache hitsSean Griffin2015-10-2012-20/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Prior to this commit, Rails makes no differentiation between whether a query uses bind parameters, and whether or not we cache that query as a prepared statement. This leads to the cache populating extremely fast in some cases, with the statements never being reused. In particular, the two problematic cases are `where(foo: [1, 2, 3])` and `where("foo = ?", 1)`. In both cases we'll end up quoting the values rather than using a bind param, causing a cache entry for every value ever used in that query. It was noted that we can probably eventually change `where("foo = ?", 1)` to use a bind param, which would resolve that case. Additionally, on PG we can change our generated query to be `WHERE foo = ANY($1)`, and pass an array for the bind param. I hope to accomplish both in the future. For SQLite and MySQL, we still end up preparing the statements anyway, we just don't cache it. The statement will be cleaned up after it is executed. On postgres, we skip the prepare step entirely, as an API is provided to execute with bind params without preparing the statement. I'm not 100% happy on the way this ended up being structured. I was hoping to use a decorator on the visitor, rather than mixing a module into the object, but the way Arel has it's visitor pattern set up makes it very difficult to extend without inheritance. I'd like to remove the duplication from the various places that are extending it, but that'll require a larger restructuring of that initialization logic. I'm going to take another look at the structure of it soon. This changes the signature of one of the adapter's internals, and will require downstream changes from third party adapters. I'm not too worried about this, as worst case they can simply add the parameter and always ignore it, and just keep their previous behavior. Fixes #21992.
* Merge pull request #21932 from kamipo/add_stored_procedure_test_in_mysql2Sean Griffin2015-10-208-22/+70
|\ | | | | Add stored procedure test in mysql2
| * Add stored procedure test in mysql2Ryuta Kamizono2015-10-156-17/+65
| |
| * Make `AbstractMysqlAdapter#version` publicRyuta Kamizono2015-10-152-5/+5
| |
* | Merge pull request #21962 from kamipo/fix_tinyblobSean Griffin2015-10-208-16/+36
|\ \ | | | | | | Fix to correctly schema dump the `tinyblob`
| * | Fix to correctly schema dump the `tinyblob`Ryuta Kamizono2015-10-158-16/+36
| | | | | | | | | | | | | | | | | | Currently `tinyblob` is dumped to `t.binary "tiny_blob", limit: 255`. But `t.binary ... limit: 255` is generating SQL to `varchar(255)`. It is incorrect. This commit fixes this problem.
* | | Add CHANGELOG entry for fix of #21955 [ci skip]Rafael Mendonça França2015-10-201-0/+6
| | |
* | | Merge pull request #21974 from ↵Rafael Mendonça França2015-10-202-5/+20
|\ \ \ | | | | | | | | | | | | | | | | | | | | jbranchaud/reorder-has-many-assocation-constraints Reorder application of has_many association constraints.
| * | | Reorder application of has_many association constraints.jbranchaud2015-10-192-1/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With `unscope!` called last, it undoes `where` constraints of the same value when the `where` is chained after the `unscope`. This is what a `rewhere` does. This is undesirable behavior. The included tests demonstrate both the `unscope(...).where(...)` behavior as well as the direct use of `rewhere(...)`. This is in reference to #21955.
* | | | Changed the order of Association constraints from where->order->unscope to ↵kal2015-10-203-1/+6
| | | | | | | | | | | | | | | | unscope->where->order
* | | | Merge pull request #22003 from yui-knk/remove_needless_require_asYves Senn2015-10-202-4/+0
|\ \ \ \ | | | | | | | | | | Delete needless `require 'active_support/deprecation'`
| * | | | Delete needless `require 'active_support/deprecation'`yui-knk2015-10-202-4/+0
| |/ / / | | | | | | | | | | | | | | | | When `require 'active_support/rails'`, 'active_support/deprecation' is automatically loaded.
* / / / Green version of moving the handling of supported arguments to `where`yui-knk2015-10-183-10/+7
|/ / / | | | | | | | | | | | | | | | | | | | | | This commit follow up of 4d8f62d. The difference from 4d8f62d are below: * Change `WhereClauseFactory` to accept `Arel::Nodes::Node` * Change test cases of `relation_test.rb`
* | | Revert "Move the handling of supported arguments to `where`"Rafael Mendonça França2015-10-172-1/+3
| | | | | | | | | | | | | | | | | | This reverts commit 4d8f62dcfa0a5157b3facbd71f75fc6639636347. Reason: This broke the build. Please recommit again when it is green.
* | | Suppress warnings of `assigned but unused variable`yui-knk2015-10-171-2/+0
| | |
* | | Move the handling of supported arguments to `where`Sean Griffin2015-10-162-3/+1
| | | | | | | | | | | | | | | | | | `WhereClauseFactory` handles all other branches based on argument types, so the code fits more naturally here, and it's just where the responsibility belongs.
* | | `where` raises ArgumentError on unsupported types.Jake Worth2015-10-163-0/+14
| | | | | | | | | | | | [#20473]
* | | [ci skip] readonly options has been removedIgnatius Reza2015-10-161-2/+0
| | |
* | | Add an immutable string type to opt out of string dupingSean Griffin2015-10-151-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This type adds an escape hatch to apps for which string duping causes unacceptable memory growth. The reason we are duping them is in order to detect mutation, which was a feature added to 4.2 in #15674. The string type was modified to support this behavior in #15788. Memory growth is really only a concern for string types, as it's the only mutable type where the act of coersion does not create a new object regardless (as we're usually returning an object of a different class). I do feel strongly that if we are going to support detecting mutation, we should do it universally for any type which is mutable. While it is less common and ideomatic to mutate strings than arrays or hashes, there shouldn't be rules or gotchas to understanding our behavior. However, I also appreciate that for apps which are using a lot of string columns, this would increase the number of allocations by a large factor. To ensure that we keep our contract, if you'd like to opt out of mutation detection on strings, you'll also be option out of mutation of those strings. I'm not completely married to the thought that strings coming out of this actually need to be frozen -- and I think the name is correct either way, as the purpose of this is to provide a string type which does not detect mutation. In the new implementation, I'm only overriding `cast_value`. I did not port over the duping in `serialize`. I cannot think of a reason we'd need to dup the string there, and the tests pass without it. Unfortunately that line was introduced at a time where I was not nearly as good about writing my commit messages, so I have no context as to why I added it. Thanks past Sean. You are a jerk.
* | | Add deprecation warning to `ActiveRecord::Relation#update`Ted Johansson2015-10-153-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | When passing an instance of `ActiveRecord::Base` to `#update`, it would internally call `#find`, resulting in a misleading deprecation warning. This change gives this deprecated use of `#update` its own, meaningful warning.
* | | freeze the column name to drop string allocations in dirty checksAaron Patterson2015-10-141-1/+1
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Dirty checking keeps a hash where the keys are the column name and the value is a dup of the value from the database[1]. This hash is kept for every AR object, which means that we dup every column name for every AR object that does dirty checking. Freezing the column name prevents the column name from being duped and reduced overall string allocations. Here is a benchmark to demonstrate: ```ruby require 'active_record' class Topic < ActiveRecord::Base end 20.times do |i| Process.waitpid fork { ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' ActiveRecord::Base.connection.instance_eval do create_table(:topics) do |t| t.string :title, limit: 250 t.string :author_name t.string :author_email_address t.string :parent_title t.string :type t.string :group i.times do |j| t.string :"aaa#{j}" end t.timestamps null: true end end ObjectSpace::AllocationTracer.setup(%i{type}) Topic.create title: "aaron" # heat cache result = ObjectSpace::AllocationTracer.trace do 10.times do |i| Topic.create title: "aaron #{i}" end end puts "#{Topic.columns.length},#{(result.find { |k,v| k.first == :T_STRING }.last.first / 10)}" } end ``` 1. https://github.com/rails/rails/blob/3ad381c3f8598d9920998c8949a96b5f62b280dd/activerecord/lib/active_record/attribute_set/builder.rb#L102
* | applies new doc guidelines to Active Record.Yves Senn2015-10-1453-458/+514
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* | fix RDoc markup in `ConnectionPool`. [ci skip]Yves Senn2015-10-141-13/+13
| |
* | add missing `:nodoc:` to `AR::Callbacks::ClassMethods`. [ci skip]Yves Senn2015-10-141-1/+1
| |
* | add missing `:nodoc:` for `AutosaveAssociation::ClassMethods` [ci skip]Yves Senn2015-10-141-1/+1
| |
* | fix broken RDoc markup. Use `<tt>` instead of `+`. [ci skip]Yves Senn2015-10-142-7/+7
| |
* | fix RDoc list markup in `DatabaseTasks`. [ci skip]Yves Senn2015-10-141-7/+7
| |
* | add missing :nodoc: to `ActiveRecord::Scoping`. [ci skip]Yves Senn2015-10-141-2/+2
| |
* | Merge pull request #21635 from sideshowcoder/ar_type_docs_fixArthur Nogueira Neves2015-10-131-1/+1
|\ \ | |/ |/| Documentation ActiveRecord Attributes API code fix
| * ActiveRecord Attributes API code fixPhilipp Fehre2015-09-151-1/+1
| | | | | | | | | | | | | | I came across this while trying it out, with the provided code the `MoneyType` does not save as it complains that `Fixnum` does not define `include?`. I think the sensible thing is to check if it already is a `Numeric`.
* | `private def` breaks RDoc. Move meathod to preserve the docs.Yves Senn2015-10-131-6/+6
| | | | | | | | | | | | | | | | | | | | | | The rdoc parser seems to trip on the `private def` construct. Public methods following a method defined with `private def` are not visible inside the module docs but are appended to the top-most module. For example the method `ActiveRecord::QueryMethods#distinct` was listed under `ActiveRecord#distinct`. /cc @sgrif
* | docs, :nodoc: `FromClause`, `QueryAttribute` and `WhereClauseFactory`.Yves Senn2015-10-133-3/+3
| | | | | | | | [ci skip]
* | docs, add missing `:nodoc: for `Associations::Builder`. [ci skip]Yves Senn2015-10-137-9/+9
| | | | | | | | | | | | This class is only used internally. We should keep it out of public documentation. This patch adds nodoc for `ActiveRecord::Associations::Builder` and everything nested within.
* | nodoc `ActiveRecord::ForeignAssociation`. [ci skip]Yves Senn2015-10-131-1/+1
| |
* | document `EagerLoadPolymorphicError`. [ci skip]Yves Senn2015-10-131-2/+4
| | | | | | | | | | | | | | | | | | This error is raised in certain situations when eager loading polymorphic associations. We even mention it in our docs. It should be included in our API. Conflicts: activerecord/lib/active_record/associations.rb
* | nodoc `ActiveRecord::Attribute::UserProvidedDefault`. [ci skip]Yves Senn2015-10-131-1/+1
| |
* | docs, recognize code examples as Ruby in `Relation::QueryMethods` [ci skip]Yves Senn2015-10-131-33/+37
| | | | | | | | | | | | | | | | Also unify the format of code example output. Only use `# =>` if the actual return value is described. Otherwise simply use `#`. Conflicts: activerecord/lib/active_record/relation/query_methods.rb
* | docs, nodoc internal Active Record `DelegateCache`. [ci skip]Yves Senn2015-10-131-3/+3
| |
* | docs, fix highlighting for code examples in calculations.rb [ci skip]Yves Senn2015-10-131-20/+20
| |
* | `:to_table` when adding a fk through `add_reference`.Yves Senn2015-10-134-3/+29
| | | | | | | | | | | | | | | | | | | | | | | | Closes #21563. The `name` argument of `add_references` was both used to generate the column name `<name>_id` and as the target table for the foreign key `name.pluralize`. It's primary purpose is to define the column name. In cases where the `to_table` of the foreign key is different than the column name we should be able to specify it individually.
* | Merge pull request #21938 from ↵Yves Senn2015-10-135-92/+107
|\ \ | | | | | | | | | | | | kamipo/move_schema_dumping_methods_into_appropriate_files Move the methods for schema dumping into `{mysql,postgresql}/schema_dumper.rb`
| * | Move the methods for schema dumping into `{mysql,postgresql}/schema_dumper.rb`Ryuta Kamizono2015-10-135-92/+107
| | | | | | | | | | | | | | | Current master branch includes many schema dumping improvements. It extract these features to the appropriate files.
* | | Merge pull request #21288 from yahonda/mysql_requires_passwordArthur Nogueira Neves2015-10-122-5/+5
|\ \ \ | |/ / |/| | Allow mysql and mysql2 tests run by database user with password
| * | Allow mysql and mysql2 tests run by database user with passwordYasuo Honda2015-08-182-5/+5
| | |
* | | Merge pull request #21931 from paul/bugfix/remove-deprecated-pg_dump-flagYves Senn2015-10-123-5/+9
|\ \ \ | | | | | | | | | | | | Remove deprecated pg_dump -i flag
| * | | Remove deprecated pg_dump -i flagPaul Sadauskas2015-10-101-1/+1
| | | |
* | | | Move schema creation class into `mysql/schema_creation.rb`Ryuta Kamizono2015-10-112-53/+59
| | | | | | | | | | | | | | | | | | | | Current master branch includes many schema creation improvements in MySQL. It extract these features to the appropriate file.
* | | | Move schema definition classes into `mysql/schema_definitions.rb`Ryuta Kamizono2015-10-112-62/+70
|/ / / | | | | | | | | | | | | Current master branch includes many schema definition improvements in MySQL. It extract these features to the appropriate file.
* | | Merge pull request #11410 from bogdan/increment-concurencyJeremy Daer2015-10-105-40/+42
|\ \ \ | | | | | | | | | | | | Make AR#increment! and #decrement! concurrency-safe
| * | | Make #increment! and #decrement! methods concurency safeBogdan Gusiev2015-10-055-40/+41
| | | |