Skip to content
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

Preloading audits is ignored when accessing specific revision #719

Open
wkirby opened this issue Jul 2, 2024 · 0 comments · May be fixed by #715
Open

Preloading audits is ignored when accessing specific revision #719

wkirby opened this issue Jul 2, 2024 · 0 comments · May be fixed by #715

Comments

@wkirby
Copy link

wkirby commented Jul 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant