Skip to content

Preloading audits is ignored when accessing specific revision #719

Description

@wkirby

Calling .revision always executes a database query, regardless of whether the audits have been preloaded, because audits_to uses the to_version scope on the audits association, which always goes back to the database to do the <= check.

This means the following code:

@posts = Post.all.include(:audits)

@posts_at_v1 = @posts.map do |post|
  post.revision(1)
end

Will generate N+1 queries as it reconstructs each Post at revision(1) --- even though the posts were preloaded.

It would greatly benefit performance if audits could be preloaded, and all the Auditor methods would do in-memory operations if possible

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions