-
Notifications
You must be signed in to change notification settings - Fork 646
Description
Extend JsInstance with methods for calling views.
SpacetimeDB/crates/core/src/host/v8/mod.rs
Line 254 in a952ba5
| impl JsInstance { |
We need an interface for the following contexts:
SQL (http/remote query):
This is a read only context. A view in this context can still use a mutable transaction, but it won't update any internal state. It can either fully evaluate the view every time, or it can check if it has a backing table and scan that.
Subscribe:
A view in this context will run in a mutable transaction. If already subscribed to and materialized, it should just return the materialized results. Otherwise we should:
- Update
st_view_argif necessary - Update
st_view_client - Evaluate the view
- Update read sets and backing table
- Return result
Unsubscribe:
A view in this context will run in a mutable transaction. The client is already subscribed so we know the result set is materialized. We should:
- Scan and return the materialized result
- Drop the materialized result (delete rows from the backing table)
- Update
st_view_client(remove subscriber) - Update
st_view_argpotentially (if no one is subscribed to this set of args)
Subscription Update:
A view in this context will run in a mutable transaction. When evaluating a view in this context, we have already checked and determined that the view is stale, hence we are always evaluating the view (not reading cached results) and updating its read set. We also must update the backing table in this case. Note that technically it is not necessary to return the result of the view to the caller because in this case the caller only cares about the table diff which it will get when downgrading the transaction before dispatching to the subscription engine.