Skip to content

Commit 3aa1a00

Browse files
committed
commentary
1 parent 734e7d4 commit 3aa1a00

File tree

7 files changed

+23
-31
lines changed

7 files changed

+23
-31
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: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ use super::{
88
tx_state::{IndexIdMap, PendingSchemaChange, TxState, TxTableForInsertion},
99
SharedMutexGuard, SharedWriteGuard,
1010
};
11-
use crate::system_tables::{
12-
system_tables, ConnectionIdViaU128, IdentityViaU256, StConnectionCredentialsFields, StConnectionCredentialsRow,
13-
StViewArgFields, StViewArgRow, StViewColumnFields, StViewFields, StViewParamFields, StViewParamRow,
14-
StViewSubFields, StViewSubRow, ST_CONNECTION_CREDENTIALS_ID, ST_VIEW_ARG_ID, ST_VIEW_COLUMN_ID, ST_VIEW_ID,
15-
ST_VIEW_PARAM_ID, ST_VIEW_SUB_ID,
16-
};
1711
use crate::traits::{InsertFlags, RowTypeForTable, TxData, UpdateFlags};
12+
use crate::{
13+
error::ViewError,
14+
system_tables::{
15+
system_tables, ConnectionIdViaU128, IdentityViaU256, StConnectionCredentialsFields, StConnectionCredentialsRow,
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,
19+
},
20+
};
1821
use crate::{
1922
error::{IndexError, SequenceError, TableError},
2023
system_tables::{
@@ -1987,29 +1990,6 @@ impl MutTxId {
19871990
.and_then(|row| row.table_id.map(|id| (id, row.is_anonymous))))
19881991
}
19891992

1990-
/// Delete the rows of a view subscribed to by `sender`
1991-
fn delete_view_rows_for_identity(&mut self, view_id: ViewId, arg_id: u64, sender: Identity) -> Result<()> {
1992-
if let Some((table_id, is_anonymous)) = self.get_table_id_for_view(view_id)? {
1993-
let value = if is_anonymous {
1994-
let none_sender = AlgebraicValue::OptionNone();
1995-
AlgebraicValue::product([none_sender, arg_id.into()])
1996-
} else {
1997-
let sender = IdentityViaU256(sender);
1998-
let some_sender = AlgebraicValue::OptionSome(sender.into());
1999-
AlgebraicValue::product([some_sender, arg_id.into()])
2000-
};
2001-
for row_pointer in self
2002-
.iter_by_col_eq(table_id, col_list![0, 1], &value)?
2003-
.map(|row_ref| row_ref.pointer())
2004-
.collect::<Vec<_>>()
2005-
.into_iter()
2006-
{
2007-
self.delete(table_id, row_pointer)?;
2008-
}
2009-
}
2010-
Ok(())
2011-
}
2012-
20131993
pub fn insert_st_client(
20141994
&mut self,
20151995
identity: Identity,

0 commit comments

Comments
 (0)