Skip to content

Commit 033329a

Browse files
change ordering to product id and paginate all products to reduce db load
1 parent a85be4e commit 033329a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

app/routes.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,11 +765,18 @@ def get_all_products():
765765
tags:
766766
- Product
767767
description: Get all products.
768+
parameters:
769+
- in: query
770+
name: page
771+
type: integer
772+
default: 1
773+
description: Page number
768774
responses:
769775
200:
770-
description: A list of products.
776+
description: A list of products for that page.
771777
"""
772-
products = Product.query.order_by(Product.name).all()
778+
page = request.args.get("page", default=1, type=int)
779+
products = Product.query.order_by(Product.id.asc()).paginate(page=page, per_page=2, error_out=False)
773780
return jsonify({"products": [product.to_json() for product in products]}), 200
774781

775782

0 commit comments

Comments
 (0)