Skip to content

Commit fcb8351

Browse files
Rewrite unoptimized remote queries
1 parent 361b4c4 commit fcb8351

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

crates/core/src/host/module_host.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,23 @@ impl ModuleHost {
10191019
let db = replica_ctx.relational_db.clone();
10201020
let subscriptions = replica_ctx.subscriptions.clone();
10211021
let auth = AuthCtx::new(replica_ctx.owner_identity, caller_identity);
1022-
log::debug!("One-off query: {query}");
1022+
1023+
const BUILDING_STATE_SQL: &str = "SELECT location_state.* FROM location_state JOIN building_state ON building_state.entity_id = location_state.entity_id";
1024+
const CLAIM_STATE_SQL: &str = "SELECT location_state.* FROM location_state JOIN claim_state ON claim_state.owner_building_entity_id = location_state.entity_id";
1025+
1026+
const OPT_BUILDING_STATE_SQL: &str = "SELECT location_state.* FROM building_state JOIN location_state ON building_state.entity_id = location_state.entity_id";
1027+
const OPT_CLAIM_STATE_SQL: &str = "SELECT location_state.* FROM claim_state JOIN location_state ON claim_state.owner_building_entity_id = location_state.entity_id";
1028+
1029+
let query = if query == BUILDING_STATE_SQL {
1030+
OPT_BUILDING_STATE_SQL.to_owned()
1031+
} else if query == CLAIM_STATE_SQL {
1032+
OPT_CLAIM_STATE_SQL.to_owned()
1033+
} else {
1034+
query
1035+
};
1036+
1037+
log::info!("One-off query: {query}");
1038+
10231039
let metrics = asyncify(move || {
10241040
db.with_read_only(Workload::Sql, |tx| {
10251041
// We wrap the actual query in a closure so we can use ? to handle errors without making

0 commit comments

Comments
 (0)