aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/integration.rb
Commit message (Collapse)AuthorAgeFilesLines
* Remove ability to specify a timestamp name for `#cache_key`Rafael Mendonça França2019-01-171-12/+3
|
* Use the full link URL instead of bit.ly [ci skip]Ryuta Kamizono2018-11-301-1/+2
|
* Merge pull request #33835 from schneems/schneems/faster_cache_versionSean Griffin2018-11-271-2/+50
|\ | | | | Use raw time string from DB to generate ActiveRecord#cache_version
| * Prefer String#ljust over String#<< for paddinglsylvester2018-10-171-3/+2
| |
| * Do not silently fail to generate a cache_versionschneems2018-10-171-6/+11
| | | | | | | | | | | | When an `updated_at` column exists on the model, but is not available on the instance (likely due to a select), we should raise an error rather than silently not generating a cache_version. Without this behavior it's likely that cache entries will not be able to be invalidated and this will happen without notice. This behavior was reported and described by @lsylvester in https://github.com/rails/rails/pull/34197#issuecomment-429668759.
| * Use raw time string from DB to generate ActiveRecord#cache_versionschneems2018-10-171-2/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, the `updated_at` field is used to generate a `cache_version`. Some database adapters return this timestamp value as a string that must then be converted to a Time value. This process requires a lot of memory and even more CPU time. In the case where this value is only being used for a cache version, we can skip the Time conversion by using the string value directly. - This PR preserves existing cache format by converting a UTC string from the database to `:usec` format. - Some databases return an already converted Time object, in those instances, we can directly use `created_at`. - The `updated_at_before_type_cast` can be a value that comes from either the database or the user. We only want to optimize the case where it is from the database. - If the format of the cache version has been changed, we cannot apply this optimization, and it is skipped. - If the format of the time in the database is not UTC, then we cannot use this optimization, and it is skipped. Some databases (notably PostgreSQL) returns a variable length nanosecond value in the time string. If the value ends in a zero, then it is truncated For instance instead of `2018-10-12 05:00:00.000000` the value `2018-10-12 05:00:00` is returned. We detect this case and pad the remaining zeros to ensure consistent cache version generation. Before: Total allocated: 743842 bytes (6626 objects) After: Total allocated: 702955 bytes (6063 objects) (743842 - 702955) / 743842.0 # => 5.4% ⚡️⚡️⚡️⚡️⚡️ Using the CodeTriage application and derailed benchmarks this PR shows between 9-11% (statistically significant) performance improvement versus the commit before it. Special thanks to @lsylvester for helping to figure out a way to preserve the usec format and for helping with many implementation details.
* | Fix cache_versioning default note (#34466)Gannon McGibbon2018-11-161-1/+1
|/ | | [ci skip]
* [ci skip] Fix typoFrancesco Rodríguez2018-10-081-1/+1
|
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+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
|
* Add option for class_attribute default (#29270)David Heinemeier Hansson2017-05-291-4/+2
| | | | | | | | | | | | * Allow a default value to be declared for class_attribute * Convert to using class_attribute default rather than explicit setter * Removed instance_accessor option by mistake * False is a valid default value * Documentation
* Fix a RuboCop offences using `rubocop -a`Koichi ITO2017-05-241-1/+0
|
* Fix `warning: assigned but unused variable - timestamp`Ryuta Kamizono2017-05-201-1/+1
|
* Add cache_key_with_version and use it in ActiveSupport::Cache.expand_cache_keyDavid Heinemeier Hansson2017-05-191-17/+26
| | | | | | This retains the existing behavior of ActiveSupport::Cache.expand_cache_key (as used by etaging) where the cache key includes the version.
* Use recyclable cache keys (#29092)David Heinemeier Hansson2017-05-181-9/+40
|
* Add missing `+` around a some literals.bogdanvlviv2016-10-271-3/+3
| | | | | | Mainly around `nil` [ci skip]
* Fix issue with `cache_key` when the named timestamp column has value nilPrathamesh Sonpatki2016-09-071-10/+13
| | | | | | | - When the named timestamp column is nil, we should just return the cache_key with model name and id similar to the behavior of implicit timestamp columns. - Fixed one of the issue mentioned in https://github.com/rails/rails/issues/26417.
* modernizes hash syntax in activerecordXavier Noria2016-08-061-1/+1
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-2/+2
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* fix to_param to maximize contentRob Biedenharn2016-07-081-2/+2
| | | | | | | | | | | | | | | | | | | | | The documentation states that parameter values longer than 20 characters will be truncated by words, but the example shows that a parameter based on "David Heinemeier Hansson" (with id: 125) becomes "125-david" when "David Heinemeier".length == 16 so why so short? The answer lies in the use of the #truncate option omission: nil which seems to have been intended to mean "nothing", but which actually causes the default string "..." to be used. This causes #truncate to cleave words until the "..." can be added and still remain within the requested size of 20 characters. The better option is omission: '' (which is probably what was originally intended). Furthermore, since the use of #parameterize will remove non-alphanumeric characters, we can maximize the useful content of the output by calling parameterize first and then giving truncate a separator: /-/ rather than a space.
* fixes #21815Maarten Jacobs2015-10-161-2/+2
| | | | | | | | | | | | | | | The default timestamp used for AR is `updated_at` in nanoseconds! (:nsec) This causes issues on any machine that runs an OS that supports nanoseconds timestamps, i.e. not-OS X, where the cache_key of the record persisted in the database (milliseconds precision) is out-of-sync with the cache_key in the ruby VM. This commit adds: A test that shows the issue, it can be found in the separate file `cache_key_test.rb`, because - model couldn't be defined inline - transactional testing needed to be turned off to get it to pass the MySQL tests This seemed cleaner than putting it in an existing testcase file. It adds :usec as a dateformat that calculates datetime in microseconds It sets precision of cache_key to :usec instead of :nsec, as no db supports nsec precision on timestamps
* [ci skip] Change 'an URL' to 'a URL' as URL doesn't have a vowel soundtanmay30112015-10-061-1/+1
|
* D HH => D H HAkira Matsuda2015-09-181-1/+1
|
* Use #model_name on instances instead of classesAmiel Martin2014-06-241-4/+4
| | | | | | This allows rails code to be more confdent when asking for a model name, instead of having to ask for the class. Rails core discussion here: https://groups.google.com/forum/#!topic/rubyonrails-core/ThSaXw9y1F8
* Fix to_param when attribute has multibyte characterrono232013-12-191-2/+4
|
* explain how `to_param` wil truncate long values. [ci skip] refs #12900.Yves Senn2013-11-151-0/+3
|
* added one test case and example for ActiveRecord::Base.to_param methodKuldeep Aggarwal2013-11-151-0/+4
|
* Addendum to #12891Javan Makhmali2013-11-141-6/+10
| | | | | | * Fix incorrectly named tests * Restore Object#to_param behavior * Ensure param is derived from a squished and truncated string
* Add AR::Base.to_param for convenient "pretty" URLs derived from a model's ↵Javan Makhmali2013-11-141-0/+31
| | | | attribute or method.
* Refactor logic to grab the max time of the list of timestamp names in #cache_keyCarlos Antonio da Silva2013-11-041-2/+2
| | | | | Reuse the already existing logic used for grabbing this information from the updated columns.
* Respect cache timestamp format when giving timestamps to #cache_keyCarlos Antonio da Silva2013-11-041-1/+2
|
* :scissors: [ci skip]Carlos Antonio da Silva2013-11-041-2/+2
|
* Extend ActiveRecord::Base#cache_key to take an optional list of timestamp ↵David Heinemeier Hansson2013-11-021-1/+9
| | | | attributes of which the highest will be used.
* Prefer find_by over dynamic finders in rdocSam Ruby2013-04-021-2/+2
|
* cache_key consults updated_on timestamp if presentBrendon Murphy2013-02-261-1/+1
| | | | | - Extract max timestamp retrieval for cache_key - Update changelog for cache_key changes
* revises the documentation of AR::Base.cache_timestamp_format [ci skip]Xavier Noria2013-02-201-2/+4
|
* Revert "Merge pull request #8989 from robertomiranda/use-rails-4-find-by"Guillermo Iguaran2013-01-181-2/+2
| | | | | This reverts commit 637a7d9d357a0f3f725b0548282ca8c5e7d4af4a, reversing changes made to 5937bd02dee112646469848d7fe8a8bfcef5b4c1.
* User Rails 4 find_byrobertomiranda2013-01-181-2/+2
|
* Allow users to choose the timestamp format in the cache keyRafael Mendonça França2012-12-101-1/+12
| | | | | | | This can be done using the class attribute cache_timestamp_format Conflicts: railties/guides/source/configuring.textile
* Cleans and removes 'Examples' tag [ci skip]Alvaro Pereyra2012-12-011-2/+0
|
* Increase `AR#cache_key` precision to nanosecondsJamie Gaskins2012-05-191-1/+1
|
* Split out most of the AR::Base code into separate modules :cake:Jon Leighton2011-12-151-0/+49