aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/journey/formatter.rb
Commit message (Collapse)AuthorAgeFilesLines
* [Action Pack] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-111-0/+1
|
* Prepare AP and AR to be frozen string friendlyKir Shatrov2017-07-061-1/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* [docs] fix ActionDispatch documentationHrvoje Šimić2017-03-131-1/+1
|
* Use `next` instead of `break`; avoid terminating whole loopJon Moss2016-12-291-1/+1
| | | | | | | | | | | | | | We want to avoid terminating the whole loop here, because it will cause parameters that should be removed to not be removed, since we are terminating early. In this specific case, `param2` is processed before `param1` due to the reversing of `route.parts`, and since `param2` fails the check on this line, it would previously cause the whole loop to fail, and `param1` would still be in `parameterized_parts`. Now, we are simply calling `next`, which is the intended behavior. Introduced by 8ca8a2d773b942c4ea76baabe2df502a339d05b1. Fixes #27454.
* Optimize Journey::Route#scoreBen Hughes2016-12-281-1/+5
| | | | | | | | Scoring routes based on constraints repeated many type conversions that could be performed in the outer loop. Determinations of score and fitness also used Array operations that required allocations. Against my benchmark with a large routeset, this reduced object allocations by over 30x and wall time by over 3x.
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
|
* Fix :stopdoc: to :startdoc: [ci skip]Ryuta Kamizono2016-10-281-1/+1
|
* Remove all Journey constant from public APIRafael Mendonça França2016-10-261-1/+3
| | | | | | There were never public API only there by mistake. [ci skip]
* Show an "unmatched constraints" error for mismatching and present paramsChris Carter2016-10-031-1/+5
| | | | | | | | | | | | Currently a misleading "missing required keys" error is thrown when a param fails to match the constraints of a particular route. This commit ensures that these params are recognised as unmatching rather than missing. Note: this means that a different error message will be provided between optimized and non-optimized path helpers, due to the fact that the former does not check constraints when matching routes. Fixes #26470.
* Add three new rubocop rulesRafael Mendonça França2016-08-161-1/+1
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* applies new string literal convention in actionpack/libXavier Noria2016-08-061-1/+1
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Refactor handling of :action default in routingAndrew White2016-02-161-2/+7
| | | | | | | | | | | | | | | | | | | | | The longstanding convention in Rails is that if the :action parameter is missing or nil then it defaults to 'index'. Up until Rails 5.0.0.beta1 this was handled slightly differently than other routing defaults by deleting it from the route options and adding it to the recall parameters. With the recent focus of removing unnecessary duplications this has exposed a problem in this strategy - we are now mutating the request's path parameters and causing problems for later url generation. This will typically affect url_for rather a named url helper since the latter explicitly pass :controller, :action, etc. The fix is to add a default for :action in the route class if the path contains an :action segment and no default is passed. This change also revealed an issue with the parameterized part expiry in that it doesn't follow a right to left order - as soon as a dynamic segment is required then all other segments become required. Fixes #23019.
* Fix route creation when format is a blank stringeileencodes2015-09-021-1/+1
| | | | | | | | | | | | | | | | | Commit bff61ba, while reducing allocations, caused a regression when an empty format is passed to a route. This can happen in cases where you're using an anchor tag, for example: `https://example.com/parent/575256966.#child_1032289285`. Because of this change `format` was getting sent in `parameterized_parts` when previously it was not included. This resulted in blank `format`'s being returned as `.` when if there was an extension included it would be `.extension`. Since there was no extension this caused incorrect URL's. The test shows this would result in `/posts/show/1.` instead of `/posts/show/1` which causes bad urls since the format is not present.
* only keep one hash of named routesAaron Patterson2015-08-141-1/+1
| | | | | The outer router object already keeps a hash of named routes, so we should just use that.
* Array#any? is slower and not the inverse of Array#empty?Jean Boussier2015-07-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ``` empty_array = [] small_array = [1] * 30 bigger_array = [1] * 300 Benchmark.ips do |x| x.report('empty !empty?') { !empty_array.empty? } x.report('small !empty?') { !small_array.empty? } x.report('bigger !empty?') { !bigger_array.empty? } x.report('empty any?') { empty_array.any? } x.report('small any?') { small_array.any? } x.report('bigger any?') { bigger_array.any? } end ``` ``` Calculating ------------------------------------- empty !empty? 132.059k i/100ms small !empty? 133.974k i/100ms bigger !empty? 133.848k i/100ms empty any? 106.924k i/100ms small any? 85.525k i/100ms bigger any? 86.663k i/100ms ------------------------------------------------- empty !empty? 8.522M (± 7.9%) i/s - 42.391M small !empty? 8.501M (± 8.5%) i/s - 42.202M bigger !empty? 8.434M (± 8.6%) i/s - 41.894M empty any? 4.161M (± 8.3%) i/s - 20.743M small any? 2.654M (± 5.2%) i/s - 13.256M bigger any? 2.642M (± 6.4%) i/s - 13.173M ``` Ref: https://github.com/rails/rails/pull/21057#discussion_r35902468
* Use delete_if instead of each; delete(key)schneems2015-07-301-3/+2
| | | | | | | | | | | | | It is slightly faster: ``` Calculating ------------------------------------- each; delete 35.166k i/100ms delete_if 36.416k i/100ms ------------------------------------------------- each; delete 478.026k (± 8.5%) i/s - 2.391M delete_if 485.123k (± 7.9%) i/s - 2.440M ```
* Remove (another) array allocationschneems2015-07-301-5/+14
| | | | | | We don't always need an array when generating a url with the formatter. We can be lazy about allocating the `missing_keys` array. This saves us: 35,606 bytes and 889 objects per request
* Remove array allocationschneems2015-07-301-2/+2
| | | | | | THe only reason we were allocating an array is to get the "missing_keys" variable in scope of the error message generator. Guess what? Arrays kinda take up a lot of memory, so by replacing that with a nil, we save: 35,303 bytes and 886 objects per request
* Avoid calling to_s on nil in journey/formatterschneems2015-07-301-2/+2
| | | | | | | | When `defaults[key]` in `generate` in the journey formatter is called, it often returns a `nil` when we call `to_s` on a nil, it allocates an empty string. We can skip this check when the default value is nil. This change buys us 35,431 bytes of memory and 887 fewer objects per request. Thanks to @matthewd for help with the readability
* Speed up journey missing_keysschneems2015-07-291-3/+15
| | | | | | | | Most routes have a `route.path.requirements[key]` of `/[-_.a-zA-Z0-9]+\/[-_.a-zA-Z0-9]+/` yet every time this method is called a new regex is generated on the fly with `/\A#{DEFAULT_INPUT}\Z/`. OBJECT ALLOCATIONS BLERG! This change uses a special module that implements `===` so it can be used in a case statement to pull out the default input. When this happens, we use a pre-generated regex. This change buys us 1,643,465 bytes of memory and 7,990 fewer objects per request.
* Speed up journey extract_parameterized_partsschneems2015-07-291-2/+3
| | | | | | | | Micro optimization: `reverse.drop_while` is slower than `reverse_each.drop_while`. This doesn't save any object allocations. Second, `keys_to_keep` is typically a very small array. The operation `parameterized_parts.keys - keys_to_keep` actually allocates two arrays. It is quicker (I benchmarked) to iterate over each and check inclusion in array manually. This change buys us 1774 fewer objects per request
* sort_by instead of sortYang Bo2015-04-081-1/+1
| | | | | | it is avoid sort errot within different and mixed keys. used `sort_by` + `block` to list parameter by keys. keep minimum changes
* Remove deprecated option `use_route` in controller testsRafael Mendonça França2015-01-041-15/+0
|
* Don't show the warning if we're already raising the error anywayGodfrey Chan2014-11-231-8/+13
| | | | | | | | | If the route set is empty, or if none of the routes matches with a score > 0, there is no point showing the deprecation message because we are already be raising the `ActionController::UrlGenerationError` mentioned in the warning. In this case it is the expected behavior and the user wouldn't have to take any actions.
* Deprecate passing an invalid name to `Formatter#generate`Godfrey Chan2014-11-231-0/+10
| | | | | | | | The internal tests that (incorrectly) relied on this were already fixed in 938d130. However, we cannot simply fix this bug because the guides prior to b7b9e92 recommended a workaround that relies on this buggy behavior. Reference #17453
* fix url generation error messageAccessd2014-10-211-1/+1
|
* `recall` should be `path_parameters`, also make it requiredAaron Patterson2014-07-171-3/+3
| | | | | | | | "recall" is a terrible name. This variable contains the parameters that we got from the path (e.g. for "/posts/1" it has :controller => "posts", :id => "1"). Since it contains the parameters we got from the path, "path_parameters" is a better name. We always pass path_parameters to `generate`, so lets make it required.
* Remove AD::Journey::Formatter#verify_required_parts!Viktar Basharymau2014-05-231-5/+0
| | | | | Nobody uses this private method, maybe it is a leftover from some old refactoring. Let's delete it.
* Merge pull request #15254 from DNNX/formatter-refactoring-3Rafael Mendonça França2014-05-221-4/+4
|\ | | | | Rename `stack` to `queue`
| * Rename `stack` to `queue`Viktar Basharymau2014-05-221-4/+4
| | | | | | | | | | | | | | Because it is used as a queue (FIFO), not as a stack (LIFO). * http://en.wikipedia.org/wiki/Stack_(abstract_data_type) * http://en.wikipedia.org/wiki/Queue_(data_structure)
* | Merge pull request #15252 from DNNX/formatter-refactoring-2Rafael Mendonça França2014-05-221-1/+1
|\ \ | | | | | | Remove unnecessary `Hash#to_a` call
| * | Remove unnecessary `Hash#to_a` callViktar Basharymau2014-05-221-1/+1
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Inspired by https://github.com/rails/rails/commit/931ee4186b877856b212b0085cd7bd7f6a4aea67 ```ruby def stat(num) start = GC.stat(:total_allocated_object) num.times { yield } total_obj_count = GC.stat(:total_allocated_object) - start puts "#{total_obj_count / num} allocations per call" end h = { 'x' => 'y' } stat(100) { h. each { |pair| pair } } stat(100) { h.to_a.each { |pair| pair } } __END__ 1 allocations per call 2 allocations per call ```
* / Use `break` instead of `next` in AD::Journey::Formatter#match_routeViktar Basharymau2014-05-221-1/+1
|/ | | | | | The array is sorted in descending order, so there is no point in iterating further if we met a negative item - all the rest will be negative too.
* do not mutate parameters, let the caller do mutationsAaron Patterson2014-05-211-0/+6
|
* we don't use this parameter for anything, so rmAaron Patterson2014-05-201-1/+1
|
* Replace map.flatten(1) with flat_mapErik Michaels-Ober2014-02-281-2/+2
|
* Show full route constraints in error messageAndrew White2014-01-051-2/+2
| | | | | | | | When an optimized helper fails to generate, show the full route constraints in the error message. Previously it would only show the contraints that were required as part of the path. Fixes #13592
* Skip Rack applications and redirects when generating urlsAndrew White2013-07-161-1/+5
| | | | | | | | | | When generating an unnamed url (i.e. using `url_for` with an options hash) we should skip anything other than standard Rails routes otherwise it will match the first mounted application or redirect and generate a url with query parameters rather than raising an error if the options hash doesn't match any defined routes. Fixes #8018
* rails -> Rails [ci skip]Prathamesh Sonpatki2013-05-091-1/+1
|
* Mark unused variables and make some style fixesAgis Anastasopoulos2013-04-081-1/+1
| | | | It'd be a nice convention to mark the unused variables like this, now that Ruby 2 will issue no warnings for such vars being unused.
* Raise correct exception now Journey is integrated.Andrew White2013-01-151-1/+6
| | | | | | | Now that Journey has been integrated into ActionDispatch we can raise the exception ActionController::UrlGenerationError directly rather than raising the internal Journey::Router::RoutingError and then have ActionDispatch::Routing::RouteSet#generate re-raise the exception.
* remove another unnecessary dupGosha Arinich2013-01-021-5/+3
|
* remove unnecessary #dupGosha Arinich2013-01-021-2/+1
|
* update AD::Journey to follow Rails coding conventionsFrancesco Rodriguez2012-12-201-84/+82
|
* :nodoc: Journey because is not part of the public API [ci skip]Francesco Rodriguez2012-12-191-6/+5
|
* Integrate Journey into Action DispatchAndrew White2012-12-191-0/+147
Move the Journey code underneath the ActionDispatch namespace so that we don't pollute the global namespace with names that may be used for models. Fixes rails/journey#49.