aboutsummaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* Improve String#strip_heredocJuanito Fatas2015-09-121-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Saves about 6 MB, about 40% faster. **strip_heredoc.rb** ```ruby require "active_support/core_ext/object/try" require "get_process_mem" class String def strip_heredoc indent = scan(/^[ \t]*(?=\S)/).min.try(:size) || 0 gsub(/^[ \t]{#{indent}}/, '') end end if ENV["MEASURE_MEMORY"] == "yes" mem = GetProcessMem.new GC.start GC.disable 10000.times do <<-MSG.strip_heredoc xhr and xml_http_request methods are deprecated in favor of `get :index, xhr: true` and `post :create, xhr: true` MSG end before = mem.mb after = mem.mb GC.enable puts "Before: #{before} MiB" puts "After: #{after} MiB" puts "Diff: #{after - before} MiB" end ``` **patched_strip_heredoc.rb** ```ruby require "active_support/core_ext/object/try" require "get_process_mem" class String def patched_strip_heredoc gsub(/^#{scan(/^[ \t]*(?=\S)/).min}/, "".freeze) end end if ENV["MEASURE_MEMORY"] == "yes" mem = GetProcessMem.new GC.start GC.disable 10000.times do <<-MSG.patched_strip_heredoc xhr and xml_http_request methods are deprecated in favor of `get :index, xhr: true` and `post :create, xhr: true` MSG end before = mem.mb after = mem.mb GC.enable puts "Before: #{before} MiB" puts "After: #{after} MiB" puts "Diff: #{after - before} MiB" end ``` **Before** ``` $ MEASURE_MEMORY=yes ruby strip_heredoc.rb Before: 44.73828125 MiB After: 44.7734375 MiB Diff: 0.03515625 MiB ``` **After** ``` $ MEASURE_MEMORY=yes ruby patched_strip_heredoc.rb Before: 37.9765625 MiB After: 38.015625 MiB Diff: 0.0390625 MiB ``` `44.7734375 - 38.015625 = 6.75` => **Saves about 6.75 MiB** **benchmark.rb** ```ruby require "benchmark/ips" require_relative "./strip_heredoc" require_relative "./patched_strip_heredoc" def original <<-MSG.strip_heredoc xhr and xml_http_request methods are deprecated in favor of `get :index, xhr: true` and `post :create, xhr: true` MSG end def patched <<-MSG.patched_strip_heredoc xhr and xml_http_request methods are deprecated in favor of `get :index, xhr: true` and `post :create, xhr: true` MSG end Benchmark.ips do |x| x.report("original") { original } x.report(" patched") { patched } x.compare! end ``` ``` $ ruby -v benchmark.rb ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14] Calculating ------------------------------------- original 5.652k i/100ms patched 6.477k i/100ms ------------------------------------------------- original 54.076k (± 5.7%) i/s - 271.296k patched 74.557k (± 6.2%) i/s - 375.666k Comparison: patched: 74557.0 i/s original: 54076.4 i/s - 1.38x slower ``` => **About 38% faster** 1. Clone rails project `git clone git@github.com:rails/rails.git` 2. Apply this patch to `activesupport/lib/active_support/core_ext/string/strip.rb` 3. `cd activesupport` 4. run `rake` 5. And tests passed: ``` ➜ activesupport $ rake /Users/Juan/.rubies/ruby-2.2.2/bin/ruby -w -I"lib:test" "/Users/Juan/.rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/rake_test_loader.rb" "test/**/*_test.rb" ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ........................................................................ ......................................................................S. SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS Finished in 15.343004s, 214.2344 runs/s, 24902.4898 assertions/s. 3287 runs, 382079 assertions, 0 failures, 0 errors, 48 skips You have skipped tests. Run with --verbose for details. ```
* Merge pull request #21585 from lachlanjc/patch-1Eileen M. Uchitelle2015-09-101-1/+1
|\ | | | | Remove RHTML reference in Action Controller docs
| * Remove RHTML reference in Action Controller docs [ci skip]Lachlan Campbell2015-09-101-1/+1
|/
* Merge pull request #21584 from claudiob/remove-hawd-docClaudio B.2015-09-101-3/+2
|\ | | | | Remove wrong doc line about AC::Parameters
| * Remove wrong doc line about AC::Parametersclaudiob2015-09-101-3/+2
| | | | | | | | | | AC::Parameters does not inherit from HashWithIndifferentAccess since #20868 by @sikachu
* | Merge pull request #21575 from y-yagi/description_of_passing_block_to_add_sourceYves Senn2015-09-101-1/+9
|\ \ | | | | | | add description of passing a block to `add_source` [ci skip]
| * | add description of passing a block to `add_source` [ci skip]yuuji.yaginuma2015-09-101-1/+9
|/ / | | | | | | block support added in 8cc01e0b2bfa75a613720c535d34e451f5de769c
* | Explicitly require AR/attribute where using itAkira Matsuda2015-09-101-0/+2
| | | | | | | | | | autoloading this could possibly cause some weird race condition when calling an AR::Attribute's singleton method on a threaded server.
* | Merge pull request #21567 from y-yagi/fix_inspect_docZachary Scott2015-09-091-1/+1
|\ \ | | | | | | fix wrong method used in the TimeWithZone#inspect method docs [ci skip]
| * | fix wrong method used in the TimeWithZone#inspect method docs [ci skip]yuuji.yaginuma2015-09-101-1/+1
| | |
* | | Merge pull request #21333 from imtayadeway/ar-querying-docsEileen M. Uchitelle2015-09-091-17/+16
|\ \ \ | | | | | | | | Improve the AR querying docs
| * | | [ci skip] Update MySQL docs reference to latestTim Wade2015-09-091-1/+1
| | | | | | | | | | | | | | | | Bumps to 5.7
| * | | [ci skip] Improve readability in AR querying guideTim Wade2015-09-091-16/+15
| | | | | | | | | | | | | | | | | | | | | | | | * rewords a few awkwardly worded sentences * adds some punctuation * adds a few missing words
* | | | remove dead code.Yves Senn2015-09-092-7/+1
| | | | | | | | | | | | | | | | | | | | | | | | The last call site of `last_version` was removed with: 838e18321118ee3ec6669217e5ea0216f79c969a
* | | | Update documentation to reflect Rack::Session::Abstract changeseileencodes2015-09-091-1/+1
| | | | | | | | | | | | | | | | | | | | `Rack::Session::Abstract::ID` is now deprecated and `Rack::Session::Abstract::Persisted` should be used instead.
* | | | Handle Content-Types that are not :json, :xml, or :url_encoded_formeileencodes2015-09-092-2/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In c546a2b this was changed to mimic how the browser behaves in a real situation but left out types that were registered. When this was changed it didn't take `text/plain` or `text/html` content types into account. This is a problem if you're manipulating the `Content-Type` headers in your controller tests, and expect a certain result. The reason I changed this to use `to_sym` is because if the `Content-Type` is not registered then the symbol will not exist. If it's one of the special types we handle that specifically (:json, :xml, or :url_encoded_form). If it's any registered type we handle it by setting the `path_parameters` and then the `request_parameters`. If the `to_sym` returns nil an error will be thrown. If the controller test sets a `Content-Type` on the request that `Content-Type` should remain in the header and pass along the filename. For example: If a test sets a content type on a post ``` @request.headers['CONTENT_TYPE'] = 'text/plain' post :create, params: { name: 'foo.txt' } ``` Then `foo.txt` should be in the `request_parameters` and params related to the path should be in the `path_parameters` and the `Content-Type` header should match the one set in the `@request`. When c546a2b was committed `text/plain` and `text/html` types were throwing a "Unknown Content-Type" error which is misleading and incorrect. Note: this does not affect how this is handled in the browser, just how the controller tests handle setting `Content-Type`.
* | | | Merge pull request #21486 from bogdan/refactor-has-many-counter-cacheEileen M. Uchitelle2015-09-094-71/+61
|\ \ \ \ | | | | | | | | | | HasManyAssociation: moved half of counter cache code to reflection
| * | | | HasManyAssociation: moved half of counter cache code to reflectionBogdan Gusiev2015-09-034-71/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Current implementation has a lot of utility methods that accept reflection call a lot of methods on it and exit. E.g. has_counter_cache?(reflection) It causes confusion and inability to cache result of the method even through it always returns the same result for the same reflection object. It can be done easier without access to the association context by moving code into reflection itself. e.g. reflection.has_counter_cache? Reflection is less complex object than association so moving code there automatically makes it simplier to understand.
* | | | | Merge pull request #21529 from rngtng/move-migrations-paths-to-database-taskYves Senn2015-09-091-7/+7
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | Use `ActiveRecord::Tasks::DatabaseTasks.migrations_paths` explicit for db tasks
| * | | | | Use `ActiveRecord::Tasks::DatabaseTasks.migrations_paths` instead of ↵Tobias Bielohlawek2015-09-071-9/+8
| | | | | | | | | | | | | | | | | | | | | | | | `Migrator.migrations_paths`
* | | | | | remove dead code.Yves Senn2015-09-091-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | This method is private API and never used. Let's remove it.
* | | | | | adjust method visibility according to it's usage.Yves Senn2015-09-091-18/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `Schema#migrations_paths` is not supposed to be public API. In fact it's only used inside `Schema` itself, so let's make it private.
* | | | | | Don't set the default argumentRafael Mendonça França2015-09-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | It is always passed in
* | | | | | Invert the conditionalRafael Mendonça França2015-09-091-1/+1
| | | | | |
* | | | | | Remove dead codeRafael Mendonça França2015-09-091-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | Usage was removed in 5c4495538b
* | | | | | Revert "Merge pull request #20080 from ↵Rafael Mendonça França2015-09-093-24/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | robertjlooby/fix_overwriting_by_dynamic_finders" This reverts commit d5ba9a42a6e93b163a49f99d739aa56820e044d0, reversing changes made to 30c503395bf6bf7db1ec0295bd661ce644628db5. Reason: This generate the dynalic finders more than one time
* | | | | | Merge pull request #20080 from robertjlooby/fix_overwriting_by_dynamic_findersRafael Mendonça França2015-09-093-3/+24
|\ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | put dynamic matchers on GeneratedAssociationMethods instead of model
| * | | | | | put dynamic matchers on the GeneratedAssociationMethods instead of modelRob Looby2015-05-083-3/+24
| | | | | | |
* | | | | | | Merge pull request #21554 from ronakjangir47/added_nodocRafael Mendonça França2015-09-091-1/+1
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | Added nodoc tag for the methods which returns object of private apis
| * | | | | | | Added nodoc for `arel` method which returns object of private api. [ci skip]Ronak Jangir2015-09-091-1/+1
| | | | | | | |
* | | | | | | | Merge pull request #20921 from pboling/fix-sql-colors-in-log-subscriberRafael Mendonça França2015-09-093-8/+126
|\ \ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix and Improve sql logging coloration in `ActiveRecord::LogSubscriber`.
| * | | | | | | | Remove extraneous `then` from case statementPeter Boling2015-07-172-14/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - CR feedback from @egilburg Additionally - Move logic for colorizing the payload name into a separate method - Make some `ActiveRecord::LogSubscriber` instance methods private for clarity: - `colorize_payload_name` - `sql_color` - `logger` - Improve Changelog Documentation GH #20885
| * | | | | | | | Improve sql logging coloration in `ActiveRecord::LogSubscriber`.Peter Boling2015-07-174-8/+144
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Improves coloring for statements like: # Become WHITE SELECT * FROM ( SELECT * FROM mytable FOR UPDATE ) ss WHERE col1 = 5; LOCK TABLE table_name IN ACCESS EXCLUSIVE MODE; # Becomes RED ROLLBACK - Reinstates the coloration of the `payload[:name]`. Instead of simple alternating colors, adds meaning: - `MAGENTA` for `"SQL"` or `blank?` payload names - `CYAN` for Model Load/Exists - Introduces specs for sql coloration. - Introduces specs for payload name coloration. GH#20885
* | | | | | | | | Merge pull request #21560 from ravindrakumawat/american-styleRafael Mendonça França2015-09-091-1/+1
|\ \ \ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | Rails documentation use american english.[ci skip]
| * | | | | | | | | Rails documentation use american english.[ci skip]ravindra kumar kumawat2015-09-091-1/+1
|/ / / / / / / / /
* | | | | | | | | Merge pull request #21559 from claudiob/timestamp-docClaudio B.2015-09-081-5/+12
|\ \ \ \ \ \ \ \ \ | |_|_|_|_|_|_|_|/ |/| | | | | | | | Fix docs of AR::Timestamp to match #15726
| * | | | | | | | Fix docs of AR::Timestamp to match #15726claudiob2015-09-081-5/+12
|/ / / / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [ci skip] @sgrif can you review when you have time? Thanks!
* | | | | | | | ensure that mutating headers will impact the content_type methodAaron Patterson2015-09-081-0/+5
| | | | | | | |
* | | | | | | | mime_type will always return a stringAaron Patterson2015-09-081-2/+1
| | | | | | | |
* | | | | | | | remove `parse_content_type` parameterAaron Patterson2015-09-081-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This method is specifically about the content type so lets remove the parameter.
* | | | | | | | avoid allocations when there is no content type setAaron Patterson2015-09-081-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | create a singleton content type that just has nils, so that we don't have to allocate a content type object all the time.
* | | | | | | | handle implicit rendering correctlyAaron Patterson2015-09-081-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If someone sets just a charset, but depends on the implicit type from rendering, this will store a strange content type header that looks like this: `; charset=blah`. This is so that when the content type header is parsed again, it will return nil for the actual type.
* | | | | | | | remove mime type lookups when parsing the content typeAaron Patterson2015-09-081-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It turns out that the response object never really cares what the mime type object is, so just use the string.
* | | | | | | | refactor content type settingAaron Patterson2015-09-081-44/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | pull content-type setting to a private method to dry it up.
* | | | | | | | make Content-Type header the canonical location for content-type infoAaron Patterson2015-09-081-34/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of storing content type information in an ivar and a header, lets move to just store the content type info in just the header.
* | | | | | | | pull content type parsing in to a methodAaron Patterson2015-09-081-7/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | we'll use this method later to lazily parse content type headers.
* | | | | | | | ensure that content type defaults to text / html when setting charsetAaron Patterson2015-09-081-0/+7
| | | | | | | |
* | | | | | | | push content_type assigment in to metalAaron Patterson2015-09-083-9/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | everything above metal really doesn't care about setting the content type, so lets rearrange these methods to be in metal.
* | | | | | | | avoid useless string allocationsAaron Patterson2015-09-082-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | _set_content_type only does something when there is a request object, otherwise the return value of _get_content_type is always ignored. This commit moves everything to the module that has access to the request object so we'll never to_s unless there is a reason
* | | | | | | | use accessors instead of manipulating the hashAaron Patterson2015-09-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in the future I would like to make the header hash read only (or at least remove guarantees that mutations will do anything).