@@ -72,7 +72,8 @@ func execCreateMicroflowGen(ctx *ExecContext, s *ast.CreateMicroflowStmt) error
7272
7373 containerID := module .ID
7474 if s .Folder != "" {
75- folderID , err := resolveFolder (ctx , module .ID , s .Folder )
75+ h , _ := getHierarchy (ctx )
76+ folderID , err := resolveFolder (ctx , module .ID , s .Folder , h )
7677 if err != nil {
7778 return mdlerrors .NewBackend ("resolve folder " + s .Folder , err )
7879 }
@@ -82,32 +83,34 @@ func execCreateMicroflowGen(ctx *ExecContext, s *ast.CreateMicroflowStmt) error
8283 qualifiedName := s .Name .Module + "." + s .Name .Name
8384
8485 // ── Existence + replace handling ──────────────────────────
86+ // Uses listMicroflowsWithContainerGen (which caches the ListAll +
87+ // GetContainerUUID pair) instead of raw ListAll + per-element
88+ // genFlowContainerModule, so that consecutive statements in the same
89+ // script reuse one batch fetch when the cache isn't invalidated.
8590 var (
8691 existing * genMf.Microflow
8792 existingContainerID model.ID
8893 existingAllowedRoles []string
8994 preserveAllowedRoles bool
9095 )
91- all , err := ctx . Microflows . ListAll ( )
96+ items , err := listMicroflowsWithContainerGen ( ctx )
9297 if err != nil {
9398 return mdlerrors .NewBackend ("check existing microflows" , err )
9499 }
95100 h , _ := getHierarchy (ctx )
96- for _ , mf := range all {
97- if mf == nil {
101+ for _ , item := range items {
102+ if item . MF == nil {
98103 continue
99104 }
100- modName := genFlowContainerModule ( ctx , h , model . ID ( mf . ID ()) )
101- if modName == s .Name .Module && mf .Name () == s .Name .Name {
105+ modName := containerModuleName ( h , item . ContainerUUID )
106+ if modName == s .Name .Module && item . MF .Name () == s .Name .Name {
102107 if ! s .CreateOrModify {
103108 return mdlerrors .NewAlreadyExistsMsg ("microflow" , qualifiedName ,
104109 "microflow '" + qualifiedName + "' already exists (use create or modify to overwrite)" )
105110 }
106- existing = mf
107- if cid , err := ctx .Microflows .GetContainerUUID (model .ID (mf .ID ())); err == nil && cid != "" {
108- existingContainerID = cid
109- }
110- existingAllowedRoles = append ([]string {}, mf .AllowedModuleRolesQualifiedNames ()... )
111+ existing = item .MF
112+ existingContainerID = item .ContainerUUID
113+ existingAllowedRoles = append ([]string {}, item .MF .AllowedModuleRolesQualifiedNames ()... )
111114 preserveAllowedRoles = true
112115 break
113116 }
@@ -260,7 +263,7 @@ func execCreateMicroflowGen(ctx *ExecContext, s *ast.CreateMicroflowStmt) error
260263 // Resolve TypeEnumeration vs TypeEntity ambiguity: a bare qualified
261264 // name (e.g. HD.Ticket) is parsed as TypeEnumeration — check the
262265 // backend to determine the true kind.
263- paramType := resolveAmbiguousDataType (ctx .Backend , p .Type )
266+ paramType := resolveAmbiguousDataType (ctx , ctx .Backend , p .Type )
264267 if dt := convertASTToGenDataType (paramType ); dt != nil {
265268 param .SetParameterType (dt )
266269 }
@@ -321,6 +324,12 @@ func execCreateMicroflowGen(ctx *ExecContext, s *ast.CreateMicroflowStmt) error
321324 ctx .trackCreatedMicroflow (s .Name .Module , s .Name .Name , model .ID (mf .ID ()), containerID , returnEntityName )
322325
323326 invalidateHierarchy (ctx )
324- invalidateMicroflowsCache (ctx )
327+ // Only invalidate microflow caches on CREATE (new name enters the
328+ // project). On MODIFY the name → ID mapping and container UUID are
329+ // unchanged, so the cached list & container UUIDs remain valid and
330+ // can serve subsequent statements without re-fetching.
331+ if existing == nil {
332+ invalidateMicroflowsCache (ctx )
333+ }
325334 return nil
326335}
0 commit comments