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

Add query summary matching #2

Merged
merged 1 commit into from
Feb 29, 2024
Merged

Add query summary matching #2

merged 1 commit into from
Feb 29, 2024

Conversation

mkllnk
Copy link
Member

@mkllnk mkllnk commented Feb 29, 2024

This has been copied from the openfoodnetwork repository and adapted slightly. It also needed one little fix.

This approach is quite different to our previous one and I'm wondering if we use User and Create instead of users and insert to stay on the higher level of Active Record. But for now this is can be a simple replacement for the openfoodnetwork spec helper and we can evolve it from there.

The code has been copied from:

https://github.com/openfoodfoundation/openfoodnetwork/blob/a692fc9d125dc2dc62fe8cd536ae5c94df6a4c28/spec/support/query_counter.rb

It has only one usage at the moment:

            query_counter = QueryCounter.new
            get :show, params: { id: order_cycle.id }, as: :json
            expect(query_counter.queries).to eq(
              {
                select: {
                  enterprise_fees: 3,
                  enterprise_groups: 1,
                  enterprises: 22,
                  exchanges: 7,
                  order_cycles: 6,
                  proxy_orders: 1,
                  schedules: 1,
                  spree_roles: 9,
                  spree_variants: 8,
                  tags: 1
                },
                update: { spree_users: 1 }
              }
            )
            query_counter.stop

https://github.com/openfoodfoundation/openfoodnetwork/blob/a692fc9d125dc2dc62fe8cd536ae5c94df6a4c28/spec/controllers/admin/order_cycles_controller_spec.rb#L135-L154

This has been copied from the openfoodnetwork repository and adapted
slightly. It also needed one little fix.

This approach is quite different to our previous one and I'm wondering
if we use `User` and `Create` instead of `users` and `insert` to stay on
the higher level of Active Record. But for now this is can be a simple
replacement for the openfoodnetwork spec helper and we can evolve it
from there.
@mkllnk mkllnk self-assigned this Feb 29, 2024
@mkllnk mkllnk marked this pull request as ready for review February 29, 2024 22:59
@mkllnk mkllnk requested a review from dacook February 29, 2024 22:59
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Nice addition!

If there's a way to achieve this using ActiveRecord instead of interpreting SQL, I think that would be much better. But this works :D

@mkllnk mkllnk merged commit dc0de2c into main Feb 29, 2024
2 checks passed
@mkllnk mkllnk deleted the summary-stats branch February 29, 2024 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants