@@ -270,6 +270,9 @@ pub struct ApprovalRecord {
270270
271271/// Insert a new workflow record. Returns the new workflow's UUID.
272272/// New workflows start as `active` and `enabled = TRUE`.
273+ ///
274+ /// NOTE: see the cache-invalidation note on [`update_workflow`]. The relay's
275+ /// creation path is [`upsert_workflow`] via event ingest. (No current callers.)
273276pub async fn create_workflow (
274277 pool : & PgPool ,
275278 community_id : CommunityId ,
@@ -607,6 +610,11 @@ pub async fn prune_scheduled_workflow_fires_before(
607610}
608611
609612/// Update a workflow's name, definition, and definition_hash.
613+ ///
614+ /// NOTE: the relay's `WorkflowEngine` caches enabled workflows per
615+ /// `(community_id, channel_id)`; a caller mutating trigger behavior must
616+ /// invalidate via `WorkflowEngine::invalidate_channel_workflows` or trigger
617+ /// matching lags the change by up to the cache TTL. (No current callers.)
610618pub async fn update_workflow (
611619 pool : & PgPool ,
612620 community_id : CommunityId ,
@@ -638,6 +646,9 @@ pub async fn update_workflow(
638646}
639647
640648/// Update a workflow's status (active -> disabled -> archived).
649+ ///
650+ /// NOTE: status gates trigger eligibility; see the cache-invalidation note on
651+ /// [`update_workflow`]. (No current callers.)
641652pub async fn update_workflow_status (
642653 pool : & PgPool ,
643654 community_id : CommunityId ,
@@ -665,6 +676,9 @@ pub async fn update_workflow_status(
665676}
666677
667678/// Enable or disable a workflow without changing its status.
679+ ///
680+ /// NOTE: `enabled` gates trigger eligibility; see the cache-invalidation note
681+ /// on [`update_workflow`]. (No current callers.)
668682pub async fn set_workflow_enabled (
669683 pool : & PgPool ,
670684 community_id : CommunityId ,
@@ -692,6 +706,10 @@ pub async fn set_workflow_enabled(
692706}
693707
694708/// Delete a workflow and all its runs/approvals (CASCADE).
709+ ///
710+ /// NOTE: see the cache-invalidation note on [`update_workflow`]. The relay's
711+ /// deletion path uses [`delete_workflow_for_owner`], which returns the
712+ /// `channel_id` needed for invalidation. (No current callers.)
695713pub async fn delete_workflow ( pool : & PgPool , community_id : CommunityId , id : Uuid ) -> Result < ( ) > {
696714 let affected = sqlx:: query ( "DELETE FROM workflows WHERE community_id = $1 AND id = $2" )
697715 . bind ( community_id. as_uuid ( ) )
@@ -712,26 +730,29 @@ pub async fn delete_workflow(pool: &PgPool, community_id: CommunityId, id: Uuid)
712730/// controlled. Keeping the owner predicate in the DELETE statement avoids a
713731/// check-then-delete race and ensures a caller cannot delete another user's
714732/// workflow just by learning its UUID.
733+ ///
734+ /// Returns the deleted workflow's `channel_id` so the caller can invalidate
735+ /// the per-channel trigger cache without a separate lookup.
715736pub async fn delete_workflow_for_owner (
716737 pool : & PgPool ,
717738 community_id : CommunityId ,
718739 id : Uuid ,
719740 owner_pubkey : & [ u8 ] ,
720- ) -> Result < ( ) > {
721- let affected = sqlx:: query (
722- "DELETE FROM workflows WHERE community_id = $1 AND id = $2 AND owner_pubkey = $3" ,
741+ ) -> Result < Option < Uuid > > {
742+ let row = sqlx:: query (
743+ "DELETE FROM workflows WHERE community_id = $1 AND id = $2 AND owner_pubkey = $3 \
744+ RETURNING channel_id",
723745 )
724746 . bind ( community_id. as_uuid ( ) )
725747 . bind ( id)
726748 . bind ( owner_pubkey)
727- . execute ( pool)
728- . await ?
729- . rows_affected ( ) ;
749+ . fetch_optional ( pool)
750+ . await ?;
730751
731- if affected == 0 {
732- return Err ( DbError :: NotFound ( format ! ( "workflow {id}" ) ) ) ;
752+ match row {
753+ Some ( row) => Ok ( row. try_get ( "channel_id" ) ?) ,
754+ None => Err ( DbError :: NotFound ( format ! ( "workflow {id}" ) ) ) ,
733755 }
734- Ok ( ( ) )
735756}
736757
737758// -- Workflow Run CRUD --------------------------------------------------------
0 commit comments