Skip to content

Commit d225c3c

Browse files
committed
Cache DAG to avoid recomputation
1 parent d89c4cd commit d225c3c

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

cmd/epp/runner/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ func (r *Runner) parseConfigurationPhaseTwo(ctx context.Context, rawConfig *conf
460460
// Add requestControl plugins
461461
r.requestControlConfig.AddPlugins(handle.GetAllPlugins()...)
462462
// Check prepare data plugins for cycles.
463-
if r.requestControlConfig.ValidatePrepareDataPlugins() != nil {
463+
if _, err := r.requestControlConfig.PrepareDataPluginGraph(); err != nil {
464464
return nil, errors.New("failed to load the configuration - prepare data plugins have cyclic dependencies")
465465
}
466466

pkg/epp/requestcontrol/request_control_config.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Config struct {
4040
responseReceivedPlugins []ResponseReceived
4141
responseStreamingPlugins []ResponseStreaming
4242
responseCompletePlugins []ResponseComplete
43+
prepareDataPluginGraph map[string][]string
4344
}
4445

4546
// WithPreRequestPlugins sets the given plugins as the PreRequest plugins.
@@ -105,11 +106,16 @@ func (c *Config) AddPlugins(pluginObjects ...plugins.Plugin) {
105106
}
106107
}
107108

108-
// ValidatePrepareDataPlugins validates the PrepareData plugins in the Config.
109-
// It builds the data dependency graph and checks for cycles.
109+
// PrepareDataPluginGraph creates and returns the data dependency graph of PrepareData plugins.
110110
// If a cycle is detected, it returns an error.
111-
func (c *Config) ValidatePrepareDataPlugins() error {
112-
_, err := prepareDataGraph(c.prepareDataPlugins)
113-
114-
return err
111+
func (c *Config) PrepareDataPluginGraph() (map[string][]string, error) {
112+
if c.prepareDataPluginGraph != nil {
113+
return c.prepareDataPluginGraph, nil
114+
}
115+
graph, err := prepareDataGraph(c.prepareDataPlugins)
116+
if err != nil {
117+
return nil, err
118+
}
119+
c.prepareDataPluginGraph = graph
120+
return graph, nil
115121
}

0 commit comments

Comments
 (0)