-
Notifications
You must be signed in to change notification settings - Fork 901
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
Discussion: timestamps waste a lot of space #1129
Comments
Knowing when a change was made is very important, but we can get that information from
PS: 56M is a lot of version records! |
Well in this codebase we'll be dropping the Which leads me back to documentation: I feel like there's got to be a better way of organizing these subjects in the docs. |
Sure, but other people will still use |
We've been pondering over removing created_at for creates / updated_at for updates for a little while now. This would save substantial space for us, 2 orders of magnitude different than these numbers. |
Have y'all considered writing an |
Looking at that currently. The first thing I noticed is the docs don't describe what happens if you don't define all three methods. |
Looks like this ends up causing an error when calling class SkipUpdatedAt
def diff(changes)
changes.except! 'updated_at'
end
end
PaperTrail.config.object_changes_adapter = SkipUpdatedAt.new
>> u = User.last
>> u.update first_name: 'b'
>> u.versions.last.object_changes
=> {"first_name"=>["a", "b"]}
>> u.versions.last.changeset
NoMethodError (undefined method `load_changeset' for #<SkipUpdatedAt:0x00007fbfc1b274a0>)
class SkipUpdatedAt
def diff(changes)
changes.except! 'updated_at'
end
def load_changeset(version)
version.changeset
end
def where_object_changes(*args)
handler = PaperTrail::Queries::Versions::WhereObjectChanges.new(*args)
handler.send :jsonb
end
end |
Would there be any issue with changing Paper Trail so it only calls the adapter if the given method exists on it? Another option would be to signal to Paper Trail that we intend to keep the original behavior. Probably the best way to do that would be with def where_object_changes(*)
throw :default
end That'd ensure that people writing adapters don't forget to implement a method accidentally. |
Fine by me.
That's a neat idea, but let's wait to see if we really need it. |
¯\(ツ)/¯ okay. in that case, would this pattern be acceptable? def execute
# ⬇️ added code
if PaperTrail.config.object_changes_adapter&.respond_to?(:where_object_changes)
return PaperTrail.config.object_changes_adapter.where_object_changes(
@version_model_class, @attributes
)
end |
Looks good to me 👍 |
It sounds like |
After #1046 / #1099, I thought it'd be interesting to see how much space
updated_at
ends up using. Turns out it represents 21% of the space used byobject_changes
(41% for updates).The total amount is even higher, of course, for those that continue to use the now-optional
object
column.I put "discussion" in the title b/c I'm not sure what Paper Trail the project should do with this information. Are there scenarios where it's important to preserve historical changes to
updated_at
?The two options would be to change Paper Trail's default behavior to exclude
updated_at
, or to document this issue, making it easy to resolve.It seems unlikely that we'd change the default behavior if only b/c of momentum. So: what should the documentation look like? I'd worry that the readme is getting a bit hard to follow w/ tips like this scattered about.
The text was updated successfully, but these errors were encountered: