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

For super admin, add pagination on /admin/enterprises #10322

Conversation

jibees
Copy link
Contributor

@jibees jibees commented Jan 25, 2023

What? Why?

Introducing pagination thanks to pagy for super admin on this page.

Also, previously, we used to use @enterprise_set = Sets::EnterpriseSet.new(collection) instead of creating set based on @collection: this leads to call the collection method twice, which was probably very time consuming. This commit fix also that.

What should we test?

  • As a super admin, we should this a faster page and paginated on /admin/enterprises. In term of performance, actually, I don't know if this could be mesurable in staging. Maybe we could compare the request time of /admin/enterprises URL via chrome|firefox inspector.
  • As a hub manager, nothing should change.

Release notes

Changelog Category: User facing changes

The title of the pull request will be included in the release notes.

@jibees jibees self-assigned this Jan 25, 2023
@jibees jibees force-pushed the 8027-performance-improvement-on-adminenterprises branch 4 times, most recently from 56230be to 5b83429 Compare January 30, 2023 08:33
Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Nice quick fix!


# These need to run before #load_resource so that @object is initialised with sanitised values
prepend_before_action :override_owner, only: :create
prepend_before_action :override_sells, only: :create

before_action :load_enterprise_set, only: :index
before_action :load_enterprise_set_on_index, only: :index
Copy link
Member

Choose a reason for hiding this comment

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

When something is happening only in one action, I often prefer to call it within that action. It keeps related code together and you can see quicker what's happening.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree 👍
84e2fbc

@jibees jibees requested a review from dacook February 2, 2023 16:03
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.

Great, I can't wait to see this in action!

app/controllers/admin/enterprises_controller.rb Outdated Show resolved Hide resolved
Enterprises are stored in `@enterprise_set` variables, and we iterate over to show the list of enterprises to super admin.

Previously, we used to use `Sets::EnterpriseSet.new(collection)` instead of creating set based on `@collection`: this leads to call the `collection` method twice, which was probably very time consuming. This commit fix also that.

+ use paginated enterprises loading on bulk update but without testing if the current user is an admin
so let's call it inside the action.
@jibees jibees force-pushed the 8027-performance-improvement-on-adminenterprises branch from 84e2fbc to 9b2ed88 Compare February 3, 2023 08:15
Comment on lines +161 to +162
@pagy, @paginated_collection = pagy(@collection)
@enterprise_set = Sets::EnterpriseSet.new(@paginated_collection, params)
Copy link
Member

Choose a reason for hiding this comment

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

I guess that @paginated_collection is not used anywhere else in the code. So by making it a local variable, it's clear that you can change the name or do whatever you like without affected other code.

On the other hand, this variable may be useful at some point. And if we publicise @pagy then why not the collection? So I don't mind this version either. It looks more consistent.

@drummer83 drummer83 self-assigned this Feb 8, 2023
@drummer83 drummer83 added the pr-staged-au staging.openfoodnetwork.org.au label Feb 8, 2023
@drummer83
Copy link
Contributor

Hi @jibees,
Thanks for this PR! This was bugging me for a long time, too!

Before staging

As admin user:
image

As super admin user (loading takes like forever):
Peek 2023-02-08 08-41

After staging

As admin user:
image

As super admin user:
Peek 2023-02-08 08-53
image

Results

  • No changes for regular admin users found. ✔️
  • Page loads much, much faster for super admin users. 🎉 ✔️
  • Buttons previous and next of pagy are working as expected. ✔️
  • Selecting pages by clicking the numbers is working as expected. ✔️

Note

  • I did not measure the performance because I am on a train and connection is unstable (no reproducible results)
  • The improvement of performance is obvious anyway.

Thanks! I think this is ready to merge! 🥳

@drummer83 drummer83 merged commit 73d98bd into openfoodfoundation:master Feb 8, 2023
@drummer83 drummer83 removed the pr-staged-au staging.openfoodnetwork.org.au label Feb 8, 2023
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.

Performance improvement on /admin/enterprises
4 participants