malerba118 / react-use-database

React hooks for easy relational data management on the client
54 stars 3 forks source link

Excessive memory consumption #8

Open malerba118 opened 5 years ago

malerba118 commented 5 years ago

Problem: Applications that load large amounts of data in a paginated manner could end up with large entity stores if no hard page refresh occurs. This is not necessarily a performance concern as entities are stored in an indexed data structure so lookups are fast, but it could lead to a big memory footprint.

Potential Solution: The only way currently to update the entities state is via the mergeEntities method, which does not provide a way to clear entities. The simplest solution to clearing old entities is to provide a database method void clear() that would reset the entity and query stores back to their initial (default) state. The developer could call this method periodically to ensure their entity/query stores do not get too big. An ideal time to call this method would be on route changes, because in theory any route could be an entrypoint to the app, at which point the stores would be empty anyway. For this reason, calling clear on route changes would be natural and would not cause any unexpected behavior because the application should already be set up to handle an empty store at these times. I propose there should just be one clear method as opposed to clearEntities and clearStoredQueries, because i can't picture a use case where one would be called without calling the other.