0

I'm building a food delivery app using AngularJS and using Parse.com as my BaaS.

After a user constructs their orders, they pay for the order and the order is then saved to Parse.com.

Since the maximum array size on Parse.com for an array column is 128KB, I kept the representation of the order as simple as possible. I have an array column for items. To identify each element in the items array, I only keep the objectId and the quantity.

Another concern of mine is to minimize Parse.com queries given that bandwidth is metered.

- for each Order
    - for each Order Item
        - for each Menu Item
            - if Order Item ID == Menu Item ID, copy Menu Item data.

I'm hard pressed to believe there is not a simpler way to do it. But most of the documentation I've seen doesn't say much about retrieving a subset of a collection by objectIds.

I believe this is the relevant page of documentation:

https://parse.com/docs/js/api/classes/Parse.Query.html

Does anyone have any insight as to what would be the best approach to solving this problem without breaking this up into multiple Parse.com queries?

EDIT: If you need to see the code, sure. It works. I just know from an algorithmic standpoint, this is totally inefficient.

1 Answer 1

1

I think you may be overlooking a much better way to structure your data.

First, to clarify a misleading statement, 128KB is the maximum size of any class object in Parse, not the maximum size of an array. This is everything except for Parse Files. Furthermore, a 128KB array would be massive and is well beyond your storage needs based on the description.

In terms of structuring your data, consider creating a class called OrderItem. Within this class you have a pointer to a MenuItem and number for the quantity. Then within your Order class, create an array of pointers to OrderItems.

The classes could be something like this:

  • Order
    • default metadata - objectId, createdAt, updatedAt, etc
    • user: pointer to user
    • itemArray: array of pointers to OrderItem
    • whatever other data you want
  • OrderItem
    • default metadata
    • menuItem: pointer to MenuItem
    • quantity: number
  • MenuItem
    • default metadata
    • food info, restaurant info, etc

You should use pointers as often as possible to avoid redundancies in your database and keep your design as consistent as possible. I'm unsure what the goal is of copying the Menu Item data in your sample code, so I will give a different example.

Using this design, you could query for all of a user's orders, including the data related to the order, by using the following:

var query = new Parse.Query("Order");
query.equalTo("user", request.user);

// Include the pointer data (dot notation used for pointer to pointer)
query.include("itemArray.menuItem");

query.find({ 
    success: function(results) {
        console.log(results);
        // Do something with results
    },
    error: function() {
        response.error("query failed");
    }
});
Sign up to request clarification or add additional context in comments.

5 Comments

I wanted to refrain from mentioning this for simplicity's sake. But there's also two other classes to account for: Topping and Beverage. Toppings may be added to items and beverages function pretty much the same as MenuItems. Would you recommend I use join tables for these as well? I'm not confident it will scale that well. The business for which I'm making this app has a lot of orders. At least 10 orders a day.
Wouldn't a Beverage be a MenuItem? As for toppings, OrderItem could have an array of pointers to the Topping class. This structure would scale perfectly fine on Parse's backend (its core is MongoDB) and would have no problem serving 10 orders/day much less 1000 orders/day
Beverage has fewer properties (e.g. no image, no description). And since it has a completely different visual treatment in the app, I separated it out to avoid the conditional logic.
Personally, I'd go for making MenuItem able to classify anything which is added as a generic OrderItem This would mean adding a Category column to MenuItem. These categories could be entry, beverage, topping, and so on
This would allow you to query for all beverages, query for all toppings, or whatever other filtering you may require in the UI

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.