ternandsparrow / wild-orchid-watch-pwa

Progressive Web App for the Wild Orchid Watch citizen science project
https://app.wildorchidwatch.org
4 stars 4 forks source link

Stop storing all remote obs in Vuex #68

Closed tomsaleeba closed 2 years ago

tomsaleeba commented 3 years ago

We currently pull all of the user's observations from iNat. As a user gets more and more observations, the size of this data will only increase. The memory usage isn't that much of a concern, although it's not great. The worry is that we store this data in Vuex and every time a mutation is comited, the whole store is saved to localStorage. In my test account, I have 750kb of remote obs data and having to continually serialise and save that is going to take its toll.

This is where we get the remote obs: https://github.com/ternandsparrow/wild-orchid-watch-pwa/blob/6da895eb65a5f5bcfa97e3fc8f4d87a1c17d1d19/src/store/obs.js#L123

Ideally we want to store as little as possible. The questions we need to address are:

  1. what fields do we need to store? Just enough to populate the obs list plus uuid and inatId?
  2. do we need to get all the user's obs every time or can we swap to a paging/lazy load approach? The reason I think we need everything (currently) is to check if an upload has completed. Perhaps we can split the refresh logic so we have one that gets obs to build the obs list and another that specifically checks if the IDs we care about have finished uploading. Except the current API doesn't allow searching by UUID, so maybe we could patch that?
  3. can we lean on workbox's cache to supply detail for a remote obs? Then we don't need to write any code to save/update a cache of remote records. We need to update the obsDetail page to get the remote data as it loads. If the user is offline, we need to handle that.
tomsaleeba commented 3 years ago

The API does allow searching by UUID, it's just not documented. This query:

https://api.inaturalist.org/v1/observations?user_login=tomsaleeba&order=desc&order_by=created_at&uuid=f98e8e99-7991-406d-b4d3-fa13c3bb1a4d,2b541ae4-21a3-4e19-8ff9-e1ef2598c8b1

...only gets the records for the two listed UUIDs.

tomsaleeba commented 2 years ago

Solved in the rewrite happening right now.