Skip to content

Commit

Permalink
chore: simplify WithUpdateParser option
Browse files Browse the repository at this point in the history
  • Loading branch information
ascandone committed Oct 23, 2024
1 parent 4d37f5a commit b4fd1b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
7 changes: 2 additions & 5 deletions internal/controller/system/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ func NewDefaultController(store Store, listener ledgercontroller.Listener, opts

type Option func(ctrl *DefaultController)

func WithUpdateParser(updateParser func(oldParser ledgercontroller.NumscriptParser) ledgercontroller.NumscriptParser) Option {
func WithParser(parser ledgercontroller.NumscriptParser) Option {
return func(ctrl *DefaultController) {
ctrl.parser = updateParser(ctrl.parser)
ctrl.parser = parser
}
}

Expand Down Expand Up @@ -173,9 +173,6 @@ func WithEnableFeatures(v bool) Option {
}

var defaultOptions = []Option{
WithUpdateParser(func(oldParser ledgercontroller.NumscriptParser) ledgercontroller.NumscriptParser {
return ledgercontroller.NewDefaultNumscriptParser()
}),
WithMeter(noopmetrics.Meter{}),
WithTracer(nooptracer.Tracer{}),
}
32 changes: 10 additions & 22 deletions internal/controller/system/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,25 @@ func NewFXModule(configuration ModuleConfiguration) fx.Option {
meterProvider metric.MeterProvider,
tracerProvider trace.TracerProvider,
) *DefaultController {
options := make([]Option, 0)

var parser ledgercontroller.NumscriptParser = ledgercontroller.NewDefaultNumscriptParser()
if configuration.NumscriptInterpreter {
options = append(options, WithUpdateParser(func(ledgercontroller.NumscriptParser) ledgercontroller.NumscriptParser {
return ledgercontroller.NewInterpreterNumscriptParser()
}))
parser = ledgercontroller.NewInterpreterNumscriptParser()
}

if configuration.NSCacheConfiguration.MaxCount != 0 {
options = append(options, WithUpdateParser(func(oldParser ledgercontroller.NumscriptParser) ledgercontroller.NumscriptParser {
if oldParser == nil {
oldParser = ledgercontroller.NewDefaultNumscriptParser()
}

return ledgercontroller.NewCachedNumscriptParser(
oldParser,
configuration.NSCacheConfiguration,
)

}))
parser = ledgercontroller.NewCachedNumscriptParser(parser, ledgercontroller.CacheConfiguration{
MaxCount: configuration.NSCacheConfiguration.MaxCount,
})
}

return NewDefaultController(
store,
listener,
append(options,
WithDatabaseRetryConfiguration(configuration.DatabaseRetryConfiguration),
WithMeter(meterProvider.Meter("core")),
WithTracer(tracerProvider.Tracer("core")),
WithEnableFeatures(configuration.EnableFeatures),
)...,
WithParser(parser),
WithDatabaseRetryConfiguration(configuration.DatabaseRetryConfiguration),
WithMeter(meterProvider.Meter("core")),
WithTracer(tracerProvider.Tracer("core")),
WithEnableFeatures(configuration.EnableFeatures),
)
}),
)
Expand Down

0 comments on commit b4fd1b9

Please sign in to comment.