Skip to content

Commit 7fea7fa

Browse files
simplify
1 parent c90f4ed commit 7fea7fa

9 files changed

Lines changed: 96 additions & 268 deletions

File tree

crates/core/src/host/module_host.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub use crate::subscription::module_subscription_manager::TransactionOffset;
2727
use crate::subscription::row_list_builder_pool::{BsatnRowListBuilderPool, JsonRowListBuilderFakePool};
2828
use crate::subscription::tx::DeltaTx;
2929
use crate::subscription::websocket_building::{BuildableWebsocketFormat, RowListBuilderSource};
30-
use crate::subscription::{execute_plan_for_view_with_params, execute_plan_with_params};
30+
use crate::subscription::{execute_plan, execute_plan_for_view};
3131
use crate::util::jobs::{AllocatedJobCore, SingleThreadedExecutor};
3232
use crate::worker_metrics::WORKER_METRICS;
3333
use anyhow::Context;
@@ -3309,7 +3309,7 @@ impl ModuleHost {
33093309
let delta_tx = DeltaTx::from(tx);
33103310
let params = ExecutionParams::from_auth(auth);
33113311
let (rows, _, metrics) = if returns_view_table && num_private_cols > 0 {
3312-
execute_plan_for_view_with_params::<F>(
3312+
execute_plan_for_view::<F>(
33133313
optimized.iter(),
33143314
num_cols,
33153315
num_private_cols,
@@ -3318,7 +3318,7 @@ impl ModuleHost {
33183318
rlb_pool,
33193319
)
33203320
} else {
3321-
execute_plan_with_params::<F>(optimized.iter(), &delta_tx, &params, rlb_pool)
3321+
execute_plan::<F>(optimized.iter(), &delta_tx, &params, rlb_pool)
33223322
}
33233323
.context("One-off queries are not allowed to modify the database")?;
33243324

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use spacetimedb_datastore::error::{DatastoreError, ViewError};
3939
use spacetimedb_datastore::execution_context::{self, ReducerContext, Workload};
4040
use spacetimedb_datastore::locking_tx_datastore::{FuncCallType, MutTxId, ViewCallInfo};
4141
use spacetimedb_datastore::traits::{IsolationLevel, Program};
42+
use spacetimedb_execution::ExecutionParams;
4243
use spacetimedb_lib::buffer::DecodeError;
4344
use spacetimedb_lib::db::raw_def::v9::{Lifecycle, ViewResultHeader};
4445
use spacetimedb_lib::de::DeserializeSeed;
@@ -213,10 +214,11 @@ pub(crate) fn run_query_for_view(
213214
tx.record_table_scan(&op, table_id);
214215
}
215216

216-
plan.base_plan().execute(&*tx, &mut metrics, &mut |row| {
217-
rows.push(row.to_product_value());
218-
Ok(())
219-
})?;
217+
plan.base_plan()
218+
.execute(&*tx, &ExecutionParams::from_auth(&auth), &mut metrics, &mut |row| {
219+
rows.push(row.to_product_value());
220+
Ok(())
221+
})?;
220222
}
221223

222224
Ok(rows)

crates/core/src/subscription/mod.rs

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use spacetimedb_client_api_messages::websocket::v1::{self as ws_v1};
1010
use spacetimedb_datastore::{
1111
db_metrics::DB_METRICS, execution_context::WorkloadType, locking_tx_datastore::datastore::MetricsRecorder,
1212
};
13-
use spacetimedb_execution::{pipelined::PipelinedProject, Datastore, DeltaStore, ExecutionParams, Row};
13+
use spacetimedb_execution::{pipelined::PipelinedProject, Datastore, DeltaStore, Row};
1414
use spacetimedb_lib::{metrics::ExecutionMetrics, Identity};
1515
use spacetimedb_physical_plan::plan::ParamResolver;
1616
use spacetimedb_primitives::{ColList, TableId};
@@ -99,27 +99,6 @@ impl MetricsRecorder for ExecutionCounters {
9999

100100
/// Execute subscription query fragments over a view.
101101
pub fn execute_plan_for_view<'p, F>(
102-
plan_fragments: impl IntoIterator<Item = &'p PipelinedProject>,
103-
num_cols: usize,
104-
num_private_cols: usize,
105-
tx: &(impl Datastore + DeltaStore),
106-
rlb_pool: &impl RowListBuilderSource<F>,
107-
) -> Result<(F::List, u64, ExecutionMetrics)>
108-
where
109-
F: BuildableWebsocketFormat,
110-
{
111-
execute_plan_for_view_with_params(
112-
plan_fragments,
113-
num_cols,
114-
num_private_cols,
115-
tx,
116-
&ExecutionParams::empty(),
117-
rlb_pool,
118-
)
119-
}
120-
121-
/// Execute subscription query fragments over a view with runtime parameters.
122-
pub fn execute_plan_for_view_with_params<'p, F>(
123102
plan_fragments: impl IntoIterator<Item = &'p PipelinedProject>,
124103
num_cols: usize,
125104
num_private_cols: usize,
@@ -133,7 +112,7 @@ where
133112
build_list_with_executor(rlb_pool, |metrics, add| {
134113
let col_list = ColList::from_iter(num_private_cols..num_cols);
135114
for fragment in plan_fragments {
136-
fragment.execute_with_params(tx, params, metrics, &mut |row| match row {
115+
fragment.execute(tx, params, metrics, &mut |row| match row {
137116
Row::Ptr(ptr) => add(ptr.project_product(&col_list)?),
138117
Row::Ref(val) => add(val.project_product(&col_list)?),
139118
})?;
@@ -144,18 +123,6 @@ where
144123

145124
/// Execute a subscription query
146125
pub fn execute_plan<'p, F>(
147-
plan_fragments: impl IntoIterator<Item = &'p PipelinedProject>,
148-
tx: &(impl Datastore + DeltaStore),
149-
rlb_pool: &impl RowListBuilderSource<F>,
150-
) -> Result<(F::List, u64, ExecutionMetrics)>
151-
where
152-
F: BuildableWebsocketFormat,
153-
{
154-
execute_plan_with_params(plan_fragments, tx, &ExecutionParams::empty(), rlb_pool)
155-
}
156-
157-
/// Execute a subscription query with runtime parameters.
158-
pub fn execute_plan_with_params<'p, F>(
159126
plan_fragments: impl IntoIterator<Item = &'p PipelinedProject>,
160127
tx: &(impl Datastore + DeltaStore),
161128
params: &impl ParamResolver,
@@ -166,7 +133,7 @@ where
166133
{
167134
build_list_with_executor(rlb_pool, |metrics, add| {
168135
for fragment in plan_fragments {
169-
fragment.execute_with_params(tx, params, metrics, add)?;
136+
fragment.execute(tx, params, metrics, add)?;
170137
}
171138
Ok(())
172139
})
@@ -252,7 +219,7 @@ where
252219
Tx: Datastore + DeltaStore,
253220
F: BuildableWebsocketFormat,
254221
{
255-
execute_plan_for_view_with_params::<F>(plan_fragments, num_cols, num_private_cols, tx, params, rlb_pool).map(
222+
execute_plan_for_view::<F>(plan_fragments, num_cols, num_private_cols, tx, params, rlb_pool).map(
256223
|(rows, num_rows, metrics)| table_update_from_rows(rows, num_rows, metrics, table_id, table_name, update_type),
257224
)
258225
}
@@ -270,7 +237,7 @@ pub fn collect_table_update<'p, F>(
270237
where
271238
F: BuildableWebsocketFormat,
272239
{
273-
execute_plan_with_params::<F>(plan_fragments, tx, params, rlb_pool).map(|(rows, num_rows, metrics)| {
240+
execute_plan::<F>(plan_fragments, tx, params, rlb_pool).map(|(rows, num_rows, metrics)| {
274241
table_update_from_rows(rows, num_rows, metrics, table_id, table_name, update_type)
275242
})
276243
}

crates/execution/src/dml.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use spacetimedb_physical_plan::plan::ParamResolver;
55
use spacetimedb_primitives::{ColId, TableId};
66
use spacetimedb_sats::size_of::SizeOf;
77

8-
use crate::{pipelined::PipelinedProject, Datastore, DeltaStore, ExecutionParams};
8+
use crate::{pipelined::PipelinedProject, Datastore, DeltaStore};
99

1010
/// A mutable datastore can read as well as insert and delete rows
1111
pub trait MutDatastore: Datastore + DeltaStore {
@@ -31,20 +31,16 @@ impl From<MutationPlan> for MutExecutor {
3131
}
3232

3333
impl MutExecutor {
34-
pub fn execute<Tx: MutDatastore>(&self, tx: &mut Tx, metrics: &mut ExecutionMetrics) -> Result<()> {
35-
self.execute_with_params(tx, &ExecutionParams::empty(), metrics)
36-
}
37-
38-
pub fn execute_with_params<Tx: MutDatastore>(
34+
pub fn execute<Tx: MutDatastore>(
3935
&self,
4036
tx: &mut Tx,
4137
params: &impl ParamResolver,
4238
metrics: &mut ExecutionMetrics,
4339
) -> Result<()> {
4440
match self {
4541
Self::Insert(exec) => exec.execute(tx, metrics),
46-
Self::Delete(exec) => exec.execute_with_params(tx, params, metrics),
47-
Self::Update(exec) => exec.execute_with_params(tx, params, metrics),
42+
Self::Delete(exec) => exec.execute(tx, params, metrics),
43+
Self::Update(exec) => exec.execute(tx, params, metrics),
4844
}
4945
}
5046
}
@@ -94,15 +90,15 @@ impl From<DeletePlan> for DeleteExecutor {
9490
}
9591

9692
impl DeleteExecutor {
97-
fn execute_with_params<Tx: MutDatastore>(
93+
fn execute<Tx: MutDatastore>(
9894
&self,
9995
tx: &mut Tx,
10096
params: &impl ParamResolver,
10197
metrics: &mut ExecutionMetrics,
10298
) -> Result<()> {
10399
// TODO: Delete by row id instead of product value
104100
let mut deletes = vec![];
105-
self.filter.execute_with_params(tx, params, metrics, &mut |row| {
101+
self.filter.execute(tx, params, metrics, &mut |row| {
106102
deletes.push(row.to_product_value());
107103
Ok(())
108104
})?;
@@ -137,14 +133,14 @@ impl From<UpdatePlan> for UpdateExecutor {
137133
}
138134

139135
impl UpdateExecutor {
140-
fn execute_with_params<Tx: MutDatastore>(
136+
fn execute<Tx: MutDatastore>(
141137
&self,
142138
tx: &mut Tx,
143139
params: &impl ParamResolver,
144140
metrics: &mut ExecutionMetrics,
145141
) -> Result<()> {
146142
let mut deletes = vec![];
147-
self.filter.execute_with_params(tx, params, metrics, &mut |row| {
143+
self.filter.execute(tx, params, metrics, &mut |row| {
148144
deletes.push(row.to_product_value());
149145
Ok(())
150146
})?;

crates/execution/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@ use spacetimedb_table::{static_assert_size, table::RowRef};
1414
pub mod dml;
1515
pub mod pipelined;
1616

17-
#[derive(Debug, Clone, Copy, Default)]
17+
#[derive(Debug, Clone, Copy)]
1818
pub struct ExecutionParams {
1919
sender: Option<Identity>,
2020
}
2121

2222
impl ExecutionParams {
23-
pub fn empty() -> Self {
24-
Self { sender: None }
25-
}
26-
2723
pub fn from_sender(sender: Identity) -> Self {
2824
Self { sender: Some(sender) }
2925
}

0 commit comments

Comments
 (0)