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

Paginate Exchange Products API endpoint #4471

Merged
merged 16 commits into from
Dec 17, 2019

Conversation

luisramos0
Copy link
Contributor

@luisramos0 luisramos0 commented Nov 18, 2019

What? Why?

Follow up from #4455
Closes #4476
This PR makes the OC pages able to handle exchanges with thousands of products by paginating the server queries to list exchange products.

More up to date demo:
http://g.recordit.co/HixXjlxPvk.gif

This PR opens up a few more major possibilities for improving performance, see isues #4480, #4481, #4482, #4487 and #4488

What should we test?

Verify the OC create and edit pages work correctly and specifically validate the list of products is loaded correctly when an exchange has more than 100 products (100 is the size of each page of products).

We should test the interaction between the load all products and the select all buttons in the exchange panel: if we click "select all" all checkboxes of the loaded products should be ticked.
One detail that may not be obvious to the user:

  • in the incoming settings, when user clicks on "select all" we need to load all products from the server and then select all the checkboxes (this process is done automatically by the page, the user sees a spinner and then all products appear loaded in the page and selected)
  • in the outgoing settings, when user clicks on "select all" we dont need to load all products before we select all - this is much faster but not all products/checkboxes will be visible in the page (only the first 100 or more if user has manually clicked "load more" or "load all")

Release notes

Changelog Category: Changed
The pages to create and edit Order Cycles can now handle enterprises providing or selling thousands of products. This is accomplished by handling the list of products in small pages instead of handling the full list of products all the time.

Dependencies

This cannot be merged before #4455

@luisramos0 luisramos0 self-assigned this Nov 18, 2019
@luisramos0 luisramos0 changed the base branch from master to oc_prods November 18, 2019 14:53
@luisramos0 luisramos0 changed the title Paginate exc prods Paginate Exchange Products API endpoint Nov 18, 2019
@luisramos0 luisramos0 changed the title Paginate Exchange Products API endpoint WIP Paginate Exchange Products API endpoint Nov 18, 2019
@luisramos0 luisramos0 force-pushed the paginate_exc_prods branch 4 times, most recently from 9a44964 to 50237ee Compare November 21, 2019 18:19
@luisramos0 luisramos0 force-pushed the paginate_exc_prods branch 2 times, most recently from 8368956 to 99cbbe6 Compare November 22, 2019 13:29
@luisramos0 luisramos0 force-pushed the paginate_exc_prods branch 4 times, most recently from 9477b55 to dfd9775 Compare November 22, 2019 18:24
@luisramos0 luisramos0 force-pushed the paginate_exc_prods branch 5 times, most recently from 090841f to 8d90e66 Compare November 26, 2019 14:41
@luisramos0 luisramos0 changed the title WIP Paginate Exchange Products API endpoint Paginate Exchange Products API endpoint Nov 26, 2019
@luisramos0 luisramos0 removed the pr-wip label Nov 26, 2019
@RachL RachL added the pr-staged-au staging.openfoodnetwork.org.au label Nov 27, 2019
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. 👍

{
results: results.total_count,
pages: results.num_pages,
results: paginated_products.total_count,
Copy link
Member

Choose a reason for hiding this comment

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

Is this the same as the count of the new endpoint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, this is products count, the new endpoint is variants count.

$scope.selectAllVariants = (exchange, selected) ->
$scope.loadAllExchangeProducts(exchange).then ->
$scope.setExchangeVariants(exchange, $scope.suppliedVariants(exchange.enterprise_id), selected)
$scope.$apply()
Copy link
Contributor

Choose a reason for hiding this comment

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

Having to manually call $scope.apply() is a code smell in Angular...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, agree. this is the only way I managed to refresh the page after the load process finishes. angular is not triggering a re-render.
anyway, this is supposed to disappear as we implement #4487


$scope.addSupplier = ($event) ->
$event.preventDefault()
OrderCycle.addSupplier $scope.new_supplier_id

# To select all variants we first need to load them all from the server
Copy link
Contributor

@Matt-Yorkley Matt-Yorkley Dec 6, 2019

Choose a reason for hiding this comment

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

Is this the best way to handle selecting all variants? Can't we decouple the saving of the "selected" state from loading all the products?

So instead of fetching and loading all the available variants in the exchange first, then sending another request to include all those variants in the exchange (and save it), can't we just have an endpoint on the server-side that handles the task of "select all the available variants in this exchange" and call that directly without doing the first step?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes! that's exactly #4487

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah sorry, I wasn't looking at all the issues at once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no problem, it's good you described the issue in your comment without looking at it :-)

@luisramos0
Copy link
Contributor Author

luisramos0 commented Dec 13, 2019

thanks @RachL
I looked at point 1 now.

Re numbers on the summary "x / y select " - I believe this is pre-existing problem and now I know why it happens. This is caused by products that changed suppliers. There are products selected in the OC that have a different supplier. Supplier caled "bb". If we change supplier again back to Dorv the numbers will become correct again. I think this can go live with this or maybe we should check if it is pre-existing. I'd open a separate issue for this.

re numbers of products - argh I have not thought about this problem! this will confuse the users... but the numbers are correct, above we see number of variants, below we see numbers of products :-(
what shall we do about this?
to change the loaded totals to number of variants instead of products, there's some extra calculation that needs to be done. it's not difficult but will take a few more hours of dev.
We could change from "376 / 400 selected" to "376 / 400 variants selected"

@luisramos0
Copy link
Contributor Author

Point 2 is a bug, those line should not show up in the simple form where we just load all the products for now.
I am fixing it now.

@luisramos0
Copy link
Contributor Author

I'd say we can skip code review as I just moved files around. Meanwhile reviews can comment/review if they think is required.
I'd say this is ready for test again: we need to recheck that the panels work on the multi exchange form and that now the simple form works and does not show the totals.

@luisramos0
Copy link
Contributor Author

I have redepoyed this last version to au staging (now running on ruby 2.3.7).

@RachL
Copy link
Contributor

RachL commented Dec 17, 2019

Alright so the error is fix! Moving to ready to go and creating the other issues.

@RachL RachL removed the pr-staged-au staging.openfoodnetwork.org.au label Dec 17, 2019
@luisramos0 luisramos0 changed the base branch from oc_prods to master December 17, 2019 13:40
@luisramos0
Copy link
Contributor Author

great, thanks @RachL
I have merged the first PR and changed the base of this one. I will wait for the master build and the build of this one to be green before I merge this one.

@luisramos0 luisramos0 merged commit 25ded0d into openfoodfoundation:master Dec 17, 2019
@luisramos0 luisramos0 deleted the paginate_exc_prods branch December 17, 2019 15:25
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.

Pagination in the OC create/edit pages when listing the products of an enterprise
4 participants