Skip to content

Optimize menu item, options, and cart queries #202

Open
@AndrewLester

Description

@AndrewLester

Currently, both the menu page and the cart page make separate queries for the menu items, options, and the users cart. Two separate strategies could be implemented to decrease the number of queries made overall.

First, making requests for the menu items and options on both pages of the site is unnecessary in sveltekit's SPA structure. Instead, let's make a request for the menu items and options inside the __layout file of routes directory, which will only run once when the user loads either the cart or menu pages. When the user switches between the two, this file won't run.

To get the data from the __layout file into the actual pages (menu and cart), you can either use Svelte's context API or a store. I recommend a store in this case.

Second, reducing the number of queries for the user's cart may be a more elaborate problem. My idea was to use the fact that a query is made to add items to a user's cart from the menu page. We can respond to this with the user's cart data so that the following redirection to the cart page will already have the necessary cart data, and doesn't have to make another request for the user's cart. If the cart page is being viewed not following a cart item add, then then the cart data must be fetched. Passing data from the cart item add to the cart page can be done using a store.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions