-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use a more precise generated cache key #939
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,15 @@ def initialize(hash={}) | |
end | ||
|
||
def cache_key | ||
"#{self.class.name.downcase}/#{self.id}-#{self.updated_at}" | ||
"#{self.class.name.downcase}/#{self.id}-#{self.updated_at.strftime("%Y%m%d%H%M%S%9N")}" | ||
end | ||
|
||
def cache_key_with_digest | ||
"#{cache_key}/#{FILE_DIGEST}" | ||
end | ||
|
||
def updated_at | ||
@attributes[:updated_at] ||= DateTime.now.to_time.to_i | ||
@attributes[:updated_at] ||= DateTime.now.to_time | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This usage of |
||
end | ||
|
||
def read_attribute_for_serialization(name) | ||
|
@@ -69,14 +69,19 @@ class ProfilePreviewSerializer < ActiveModel::Serializer | |
|
||
Post = Class.new(Model) | ||
Like = Class.new(Model) | ||
Comment = Class.new(Model) | ||
Author = Class.new(Model) | ||
Bio = Class.new(Model) | ||
Blog = Class.new(Model) | ||
Role = Class.new(Model) | ||
User = Class.new(Model) | ||
Location = Class.new(Model) | ||
Place = Class.new(Model) | ||
Comment = Class.new(Model) do | ||
# Uses a custom non-time-based cache key | ||
def cache_key | ||
"#{self.class.name.downcase}/#{self.id}" | ||
end | ||
end | ||
|
||
module Spam; end | ||
Spam::UnrelatedLink = Class.new(Model) | ||
|
@@ -143,7 +148,7 @@ def slug | |
LikeSerializer = Class.new(ActiveModel::Serializer) do | ||
attributes :id, :time | ||
|
||
belongs_to :post | ||
belongs_to :likeable | ||
end | ||
|
||
LocationSerializer = Class.new(ActiveModel::Serializer) do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This used to be able to be
assert_equal
because the cache key wasn't a high enough resolution to detect the change. This was actually incorrect (and/or bad caching), so at a minimum I changed the test to assert on the correct result, which it now receives.