@@ -25,7 +25,7 @@ use anyhow::Context;
2525use bytes:: Bytes ;
2626use spacetimedb_datastore:: locking_tx_datastore:: { FuncCallType , MutTxId , ViewCallInfo } ;
2727use spacetimedb_lib:: { ConnectionId , Identity , RawModuleDef , Timestamp } ;
28- use spacetimedb_primitives:: { ColId , IndexId , ProcedureId , TableId } ;
28+ use spacetimedb_primitives:: { ColId , IndexId , ProcedureId , TableId , ViewFnPtr } ;
2929use spacetimedb_sats:: bsatn;
3030use spacetimedb_schema:: def:: ModuleDef ;
3131use spacetimedb_schema:: identifier:: Identifier ;
@@ -752,19 +752,22 @@ fn refresh_views(
752752
753753 for view_call in views_for_refresh {
754754 let res: SysCallResult < ( ) > = ( || {
755- let view_def = module_def
756- . get_view_by_id ( view_call. fn_ptr , view_call. sender . is_none ( ) )
757- . ok_or_else ( || {
758- TypeError ( format ! (
759- "view with fn_ptr `{}` not found while refreshing procedure transaction" ,
760- view_call. fn_ptr
761- ) )
762- . throw ( scope)
763- } ) ?;
755+ let resolved = crate :: host:: module_host:: resolve_view_for_refresh (
756+ tx. as_ref ( ) . expect ( "procedure tx missing during view refresh" ) ,
757+ module_def,
758+ & view_call,
759+ )
760+ . map_err ( |err| TypeError ( format ! ( "view refresh failed after procedure call: {err}" ) ) . throw ( scope) ) ?;
761+
762+ let table_id = resolved. table_id ;
763+ let view_def = resolved. view_def ;
764+ let view_name = & view_def. name ;
765+ let fn_ptr = view_def. fn_ptr ;
764766
765767 let current_tx = tx. take ( ) . expect ( "procedure tx missing during view refresh" ) ;
766- let ( next_tx, call_result) =
767- tx_slot. set ( current_tx, || call_view ( scope, hooks, & view_call, & view_def. name ) ) ;
768+ let ( next_tx, call_result) = tx_slot. set ( current_tx, || {
769+ call_view ( scope, hooks, & view_call, & view_name, table_id, fn_ptr)
770+ } ) ;
768771 tx = Some ( next_tx) ;
769772 let return_data = call_result?;
770773
@@ -819,7 +822,7 @@ fn refresh_views(
819822 . materialize_view (
820823 tx. as_mut ( )
821824 . expect ( "procedure tx missing while materializing authenticated view" ) ,
822- view_call . table_id ,
825+ table_id,
823826 sender,
824827 rows,
825828 )
@@ -828,7 +831,7 @@ fn refresh_views(
828831 . materialize_anonymous_view (
829832 tx. as_mut ( )
830833 . expect ( "procedure tx missing while materializing anonymous view" ) ,
831- view_call . table_id ,
834+ table_id,
832835 rows,
833836 )
834837 . map_err ( NodesError :: from) ?,
@@ -857,6 +860,8 @@ fn call_view(
857860 hooks : & HookFunctions < ' _ > ,
858861 view_call : & ViewCallInfo ,
859862 view_name : & Identifier ,
863+ table_id : TableId ,
864+ fn_ptr : ViewFnPtr ,
860865) -> SysCallResult < ViewReturnData > {
861866 let prev_func_type = get_env ( scope) ?
862867 . instance_env
@@ -871,8 +876,8 @@ fn call_view(
871876 ViewOp {
872877 name : view_name,
873878 view_id : view_call. view_id ,
874- table_id : view_call . table_id ,
875- fn_ptr : view_call . fn_ptr ,
879+ table_id,
880+ fn_ptr,
876881 args : & args,
877882 sender : & sender,
878883 timestamp : Timestamp :: now ( ) ,
@@ -884,8 +889,8 @@ fn call_view(
884889 AnonymousViewOp {
885890 name : view_name,
886891 view_id : view_call. view_id ,
887- table_id : view_call . table_id ,
888- fn_ptr : view_call . fn_ptr ,
892+ table_id,
893+ fn_ptr,
889894 args : & args,
890895 timestamp : Timestamp :: now ( ) ,
891896 } ,
0 commit comments