[Mobile Local Storage] Store entire database table or just the records that I need?

Hi all.

Imagine you have the following scenario: you have a group of orders, and each order is going to be delivered by a company. I want to store both the order and the company details.

When I am fetching the data to store in the local storage of my device, what is the best solution?

1) Get all my orders, check the list of distinct company ids of those orders, and fetch those companies only

2) Get all my orders with the join condition with the company and store everything in a Local Order entity

3) Get all my orders and all the companies that are registered in the database

As I see, all 3 have advantages and disadvantages, but I would probably chose the first one (more processing but better local storage usage). With the second option I will probably have too many times the company details, and the third option might result in a very high number of companies that will never be displayed.

What do you think?



Hi mariap,

Who will use the app? What that person needs to see?


Eduardo Jauch

The user that is going to have access to the app must be able to see both the order and the company details for each order of that user.

option 3 in this case is not practical as information will never be accessed by the user and you will have to implement local logic to control access. It will be slower and harder to maintain.

I would recommend option 2 where you have 1 local entity that has all information about orders and companies. Though companies information will be repetitive if different orders were assigned to the same company. In this case you have minimum client side logic and joins. If companies details information is not displayed on same screen as orders you can then have 2 local entities for orders and companies and fetch company info by id when need to shoe details.
So depending of the information you present on the screen you can have some attributes with duplicated data (company name for example) and some in a separate local entity. 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.