SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

Clear materialized view tables async

Open joshua-spacetime opened this issue 1 month ago • 3 comments

When clients unsubscribe or disconnect, we update the st_view_sub system table, but we don't clear the backing table or read sets. We should have an async task that does this cleanup periodically.

joshua-spacetime avatar Nov 06 '25 07:11 joshua-spacetime

Is it neccessary to do it asynchoronously? Can we not do it within same transaction in which unsuscribe_view happens?

Shubham8287 avatar Nov 11 '25 09:11 Shubham8287

@Shubham8287 Doing it synchronously would require a larger refactor, since views are evaluated using a mutable transaction whereas unsubscribes use read-only transactions.

joshua-spacetime avatar Nov 11 '25 09:11 joshua-spacetime

@Shubham8287 Doing it synchronously would require a larger refactor, since views are evaluated using a mutable transaction whereas unsubscribes use read-only transactions.

Umm, it is working with mutable transactions - https://github.dev/clockworklabs/SpacetimeDB/blob/e0b8e6f2654c9c67f0cbb11334de31434949adfc/crates/core/src/subscription/module_subscription_actor.rs#L1035.

Are you talking about somewhere else?

Shubham8287 avatar Nov 11 '25 09:11 Shubham8287