Skip to content

Commit ad03696

Browse files
committed
commentary
1 parent dff305f commit ad03696

File tree

7 files changed

+17
-80
lines changed

7 files changed

+17
-80
lines changed

crates/core/src/db/relational_db.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ use spacetimedb_datastore::locking_tx_datastore::state_view::{
2121
IterByColEqMutTx, IterByColRangeMutTx, IterMutTx, IterTx, StateView,
2222
};
2323
use spacetimedb_datastore::locking_tx_datastore::{MutTxId, TxId};
24-
use spacetimedb_datastore::system_tables::ST_VIEW_ID;
25-
use spacetimedb_datastore::system_tables::{system_tables, StModuleRow, StViewRow};
24+
use spacetimedb_datastore::system_tables::{system_tables, StModuleRow};
2625
use spacetimedb_datastore::system_tables::{StFields, StVarFields, StVarName, StVarRow, ST_MODULE_ID, ST_VAR_ID};
2726
use spacetimedb_datastore::traits::{
2827
InsertFlags, IsolationLevel, Metadata, MutTx as _, MutTxDatastore, Program, RowTypeForTable, Tx as _, TxDatastore,

crates/core/src/host/module_host.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ pub struct CallViewParams {
546546
/// The expected return type of the view, used for deserialization.
547547
/// This type information is obtained from the [`ModuleDef`].
548548
pub return_type: AlgebraicType,
549+
/// Whether the view is being called anonymously (i.e., without a client identity).
549550
pub is_anonymous: bool,
550551
}
551552

crates/core/src/host/wasm_common/module_host_actor.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ impl InstanceCommon {
726726
}
727727
}
728728

729+
/// Calls a function (reducer, view) and performs energy monitoring.
729730
fn call_function<F, R: FunctionResult>(
730731
&mut self,
731732
caller_identity: Identity,
@@ -768,6 +769,11 @@ impl InstanceCommon {
768769
(tx, result)
769770
}
770771

772+
/// Execute a view.
773+
///
774+
/// Similar to `call_reducer_with_tx`, but for views.
775+
/// unlike to `call_reducer_with_tx`, It does not handle `tx`creation or commit,
776+
/// It returns the updated `tx` instead.
771777
fn call_view_with_tx(
772778
&mut self,
773779
replica_ctx: &ReplicaContext,

crates/core/src/host/wasmtime/wasm_instance_env.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ const STANDARD_BYTES_SINK: u32 = 1;
126126
type WasmResult<T> = Result<T, WasmError>;
127127
type RtResult<T> = anyhow::Result<T>;
128128

129+
/// The type of function call being performed.
129130
pub enum FuncCallType {
130131
Reducer,
131132
Procedure,

crates/core/src/host/wasmtime/wasmtime_module.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ fn handle_error_sink_code(code: i32, error: Vec<u8>) -> Result<(), Box<str>> {
9797
}
9898
}
9999

100+
/// Handle the return code from a function using a result sink.
101+
///
102+
/// On success, returns the result bytes.
103+
/// On failure, returns the error message.
100104
fn handle_result_sink_code(code: i32, result: Vec<u8>) -> Result<Vec<u8>, Box<str>> {
101105
match code {
102106
0 => Ok(result),

crates/core/src/subscription/module_subscription_actor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ impl ModuleSubscriptions {
197197
}
198198
}
199199

200+
/// Should be called once to initialize the `ModuleSubscriptions` with a `ModuleHost` receiver.
200201
pub fn init(&self, module_host: watch::Receiver<ModuleHost>) {
201202
self.module_rx
202203
.set(module_host)

crates/datastore/src/locking_tx_datastore/mut_tx.rs

Lines changed: 3 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,14 @@ use super::{
88
tx_state::{IndexIdMap, PendingSchemaChange, TxState, TxTableForInsertion},
99
SharedMutexGuard, SharedWriteGuard,
1010
};
11-
<<<<<<< HEAD
12-
use crate::system_tables::{
13-
system_tables, ConnectionIdViaU128, StConnectionCredentialsFields, StConnectionCredentialsRow, StViewColumnFields,
14-
StViewFields, StViewParamFields, StViewParamRow, ST_CONNECTION_CREDENTIALS_ID, ST_VIEW_COLUMN_ID, ST_VIEW_ID,
15-
ST_VIEW_PARAM_ID,
16-
};
17-
=======
18-
>>>>>>> d533f9c4c (Shub/view interface (#3561))
1911
use crate::traits::{InsertFlags, RowTypeForTable, TxData, UpdateFlags};
2012
use crate::{
2113
error::ViewError,
2214
system_tables::{
2315
system_tables, ConnectionIdViaU128, IdentityViaU256, StConnectionCredentialsFields, StConnectionCredentialsRow,
24-
StViewArgFields, StViewArgRow, StViewClientFields, StViewClientRow, StViewColumnFields, StViewFields,
25-
StViewParamFields, StViewParamRow, ST_CONNECTION_CREDENTIALS_ID, ST_VIEW_ARG_ID, ST_VIEW_CLIENT_ID,
26-
ST_VIEW_COLUMN_ID, ST_VIEW_ID, ST_VIEW_PARAM_ID,
16+
StViewArgFields, StViewArgRow, StViewClientRow, StViewColumnFields, StViewFields, StViewParamFields,
17+
StViewParamRow, ST_CONNECTION_CREDENTIALS_ID, ST_VIEW_ARG_ID, ST_VIEW_CLIENT_ID, ST_VIEW_COLUMN_ID, ST_VIEW_ID,
18+
ST_VIEW_PARAM_ID,
2719
},
2820
};
2921
use crate::{
@@ -1853,34 +1845,6 @@ impl<'a, I: Iterator<Item = RowRef<'a>>> Iterator for FilterDeleted<'a, I> {
18531845
}
18541846

18551847
impl MutTxId {
1856-
/// Delete view data and metadata for a client connection
1857-
pub fn delete_view_data_for_client(&mut self, sender: Identity, connection_id: ConnectionId) -> Result<()> {
1858-
for row in self.delete_st_view_client_rows(sender, connection_id)? {
1859-
if !self.is_identity_subscribed_to_view_args(row.view_id, row.arg_id, sender)? {
1860-
self.delete_view_rows_for_identity(row.view_id, row.arg_id, sender)?;
1861-
}
1862-
}
1863-
Ok(())
1864-
}
1865-
1866-
/// Delete and return the rows in `st_view_client` for a client connection
1867-
fn delete_st_view_client_rows(
1868-
&mut self,
1869-
sender: Identity,
1870-
connection_id: ConnectionId,
1871-
) -> Result<Vec<StViewClientRow>> {
1872-
let sender = IdentityViaU256(sender);
1873-
let conn_id = ConnectionIdViaU128(connection_id);
1874-
let cols = col_list![StViewClientFields::Identity, StViewClientFields::ConnectionId];
1875-
let value = AlgebraicValue::product([sender.into(), conn_id.into()]);
1876-
self.iter_by_col_eq(ST_VIEW_CLIENT_ID, cols, &value)?
1877-
.map(|row_ref| StViewClientRow::try_from(row_ref).map(|row| (row, row_ref.pointer())))
1878-
.collect::<Result<Vec<_>>>()?
1879-
.into_iter()
1880-
.map(|(row, ptr)| self.delete(ST_VIEW_CLIENT_ID, ptr).map(|_| row))
1881-
.collect()
1882-
}
1883-
18841848
/// Get or insert view argument into `ST_VIEW_ARG_ID`.
18851849
pub fn get_or_insert_st_view_arg(&mut self, args: &Bytes) -> Result<u64> {
18861850
let bytes_av = AlgebraicValue::Bytes(args.to_vec().into());
@@ -1926,22 +1890,6 @@ impl MutTxId {
19261890
Ok(arg_id)
19271891
}
19281892

1929-
/// Is anyone is subscribed to the view arguments identified by `arg_id`
1930-
fn is_identity_subscribed_to_view_args(&self, view_id: ViewId, arg_id: u64, sender: Identity) -> Result<bool> {
1931-
Ok(self
1932-
.iter_by_col_eq(
1933-
ST_VIEW_CLIENT_ID,
1934-
col_list![
1935-
StViewClientFields::ViewId,
1936-
StViewClientFields::ArgId,
1937-
StViewClientFields::Identity
1938-
],
1939-
&AlgebraicValue::product([view_id.into(), arg_id.into(), sender.into()]),
1940-
)?
1941-
.next()
1942-
.is_some())
1943-
}
1944-
19451893
/// Lookup a row in `st_view` by its primary key
19461894
fn st_view_row(&self, view_id: ViewId) -> Result<Option<StViewRow>> {
19471895
self.iter_by_col_eq(ST_VIEW_ID, col_list![StViewFields::ViewId], &view_id.into())?
@@ -1958,29 +1906,6 @@ impl MutTxId {
19581906
.and_then(|row| row.table_id.map(|id| (id, row.is_anonymous))))
19591907
}
19601908

1961-
/// Delete the rows of a view subscribed to by `sender`
1962-
fn delete_view_rows_for_identity(&mut self, view_id: ViewId, arg_id: u64, sender: Identity) -> Result<()> {
1963-
if let Some((table_id, is_anonymous)) = self.get_table_id_for_view(view_id)? {
1964-
let value = if is_anonymous {
1965-
let none_sender = AlgebraicValue::OptionNone();
1966-
AlgebraicValue::product([none_sender, arg_id.into()])
1967-
} else {
1968-
let sender = IdentityViaU256(sender);
1969-
let some_sender = AlgebraicValue::OptionSome(sender.into());
1970-
AlgebraicValue::product([some_sender, arg_id.into()])
1971-
};
1972-
for row_pointer in self
1973-
.iter_by_col_eq(table_id, col_list![0, 1], &value)?
1974-
.map(|row_ref| row_ref.pointer())
1975-
.collect::<Vec<_>>()
1976-
.into_iter()
1977-
{
1978-
self.delete(table_id, row_pointer)?;
1979-
}
1980-
}
1981-
Ok(())
1982-
}
1983-
19841909
pub fn insert_st_client(
19851910
&mut self,
19861911
identity: Identity,

0 commit comments

Comments
 (0)