8000 Make count query optimisation work when using decorate_with by irmela · Pull Request #5811 · activeadmin/activeadmin · GitHub
[go: up one dir, main page]

Skip to content

Make count query optimisation work when using decorate_with #5811

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

Conversation

irmela
Copy link
Contributor
@irmela irmela commented Jul 24, 2019

#3848 introduced a great performance improvement for pagination total_count. After #4068 this optimization was not available when using decorate_with.

This is another approach of #5389 with minimal change. Please let me know in case I missed something.

@deivid-rodriguez
Copy link
< 8000 div class="d-none d-sm-flex"> Member

Is it possible to add a test?

@irmela
Copy link
Contributor Author
irmela commented Jul 29, 2019

@deivid-rodriguez I'm not really sure what would be a good test case for that. I could add a unit test:

# spec/unit/resource_controller/decorators_spec.rb

it 'delegates offset method' do
  expect(applied).to respond_to(:offset)
end

But I don't think this provides much value. I would appreciate some guidance on how to best test this change 🙏

@deivid-rodriguez
Copy link
Member

Yeah, I see how a proper test can be difficult. I guess ideally we should test that when using decorate_with on a resource, pagination produces no SELECT COUNT queries. We could leverage https://github.com/civiccc/db-query-matchers for that, but it still seems tricky.

I'll look into this manually and consider merging without a test.

One question that comes to mind at first sight is whether we can undo #4068 if we include this patch.

@irmela
Copy link
Contributor Author
irmela commented Jul 31, 2019

One question that comes to mind at first sight is whether we can undo #4068 if we include this patch.

I will look into that.

@irmela
Copy link
Contributor Author
irmela commented Jul 31, 2019

I tried to investigate if the issue fixed by #4068 still exists with this change but it feels a little like #4068 got merged without any deeper understanding of why the issue occurred. That makes it super hard to reproduce so I didn't really come up with an answer to the question if we can revert the change ( && collection.respond_to?(:offset)).

@deivid-rodriguez
Copy link
Member

You mentioned that the regression this PR is fixing was created after #4068 was merged. So if after reverting #4068 the regression is still fixed, and no tests are broken, I would undo it.

@irmela
Copy link
Contributor Author
irmela commented Jul 31, 2019

@deivid-rodriguez I reverted #4068 and tests are passing.

@deivid-rodriguez
Copy link
Member

Thanks @irmela! I'll have a look at this soon 👍.

@deivid-rodriguez deivid-rodriguez force-pushed the make-count-query-optimisation-work-when-using-decorate-with branch from f3fac34 to 652ead2 Compare September 12, 2019 20:02
@deivid-rodriguez deivid-rodriguez force-pushed the make-count-query-optimisation-work-when-using-decorate-with branch from 652ead2 to 8e24320 Compare September 15, 2019 06:58
@deivid-rodriguez
Copy link
Member

I added a test for this change! Setting this as ready.

Copy link
Member
@javierjulio javierjulio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

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 this pull request may close these issues.

3 participants
0