Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support using RxDB as an offline cache rather than a offline-first database #6

Open
marceljuenemann opened this issue Apr 3, 2023 · 0 comments

Comments

@marceljuenemann
Copy link
Owner

On top of the push-only mode described in #5, another alternative to the offline-first paradigm would be to use RxDB more like an offline cache. Basically, instead of fetching all data, we only update the RxDB with the results from Supabase whenever we make a query. So RxDB will only contain the subset of the Supabase that the user has actually viewed.

The algorithm for querying would look something like this:

  1. If offline, just serve the query from RxDB
  2. Otherwise, make sure any pending local changes are pushed to Supabase already
  3. Perform the query to RxDB and Supabase in parallel. Assuming we're returning an Observable, you could return the cached RxDB results first and then follow up with the Supabase results
  4. Once both have returned, update the state of the RxDB cache as follows:
    • Documents that are part of both the RxDB and Supabase result will be updated to match the Supabase state
    • Documents in the Supabase result that weren't in RxDB will be inserted to RxDB
    • Documents in the RxDB result that weren't in Supabase will be deleted from RxDB

In this paradigm, you would not need _modified or _deleted fields in the database. However, you would need a completely new API for querying that can translate to both RxDB and Supabase queries. So simple equality and inequality checks would work, but nothing too advanced. In fact, implementing LIMIT might already be tricky (but I think it's possible)

RxDB and its replication mechanism weren't really designed for something like this, but I do think it would be possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant