autoresearch iter 15: stop CORS from querying the database on every request

isOriginAllowed read server_address from w_system_configs for every request
carrying an Origin header — one uncached primary-DB round-trip plus a split
and trim loop per browser request, while sibling config reads in the storage
driver are already TTL cached. Read it through the shared CacheService with
the same 5s window, falling back to the database when no cache is bound.
driver_http now binds CacheService in Apply the way it already binds DBService.
This commit is contained in:
ryan
2026-08-29 08:44:37 +08:00
parent 2654eb6e2c
commit 2c415638fd
4 changed files with 173 additions and 4 deletions
@@ -110,6 +110,19 @@ func (p *Plugin) Apply(ctx *core.Context) error {
return nil
})
// Bind CacheService from Context
if cache, err := core.Inject[contracts.CacheService](ctx); err == nil && cache != nil {
setCacheService(cache)
} else {
core.When[contracts.CacheService](ctx, func(cache contracts.CacheService) {
setCacheService(cache)
})
}
ctx.OnDispose(func() error {
setCacheService(nil)
return nil
})
ctx.OnDispose(func() error {
shutdownCtx, cancel := context.WithTimeout(context.Background(), p.shutdownTimeout)
defer cancel()