From fdee70e51eaebbf6474eb50976ec2ac245b29dfb Mon Sep 17 00:00:00 2001 From: ziminis Date: Mon, 30 Nov 2026 13:53:34 +0700 Subject: [PATCH] MSP-8299 remove cache --- service/variable/service.go | 49 ++++++++++--------------------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/service/variable/service.go b/service/variable/service.go index c15dcb8..16e6357 100644 --- a/service/variable/service.go +++ b/service/variable/service.go @@ -3,7 +3,6 @@ package variable import ( "context" "strings" - "sync" "time" "isp-config-service/domain" @@ -38,12 +37,11 @@ type SchemaRepo interface { } type Service struct { - repo Repo - configRepo ConfigRepo - eventRepo EventRepo - schemaRepo SchemaRepo - logger log.Logger - uiPathsCache *uiPathsCache + repo Repo + configRepo ConfigRepo + eventRepo EventRepo + schemaRepo SchemaRepo + logger log.Logger } func NewService( @@ -54,27 +52,14 @@ func NewService( logger log.Logger, ) Service { return Service{ - repo: repo, - configRepo: configRepo, - eventRepo: eventRepo, - schemaRepo: schemaRepo, - logger: logger, - uiPathsCache: &uiPathsCache{entries: make(map[string]cachedUIPaths)}, + repo: repo, + configRepo: configRepo, + eventRepo: eventRepo, + schemaRepo: schemaRepo, + logger: logger, } } -// cachedUIPaths is the module's ui-exposed leaf paths for a schema version. -type cachedUIPaths struct { - version string - paths []string -} - -// uiPathsCache caches ui-exposed paths per module, invalidated on schema version change. -type uiPathsCache struct { - mu sync.Mutex - entries map[string]cachedUIPaths -} - func (s Service) All(ctx context.Context) ([]domain.Variable, error) { variables, err := s.repo.All(ctx) if err != nil { @@ -296,10 +281,9 @@ func (s Service) SaveVariableLinks(ctx context.Context, configId string, links [ return nil } -// uiPaths returns the canonical paths of the module's ui-exposed leaves, -// cached per module and schema version. A module without a schema (or with a -// schema without the keyword) yields an empty set, so rendering behaves as -// before. +// uiPaths returns the canonical paths of the module's ui-exposed leaves. A +// module without a schema (or with a schema without the keyword) yields an +// empty set, so rendering behaves as before. func (s Service) uiPaths(ctx context.Context, moduleId string) ([]string, error) { schemaRow, err := s.schemaRepo.GetByModuleId(ctx, moduleId) if err != nil { @@ -309,17 +293,10 @@ func (s Service) uiPaths(ctx context.Context, moduleId string) ([]string, error) return nil, nil } - s.uiPathsCache.mu.Lock() - defer s.uiPathsCache.mu.Unlock() - if cached, ok := s.uiPathsCache.entries[moduleId]; ok && cached.version == schemaRow.ModuleVersion { - return cached.paths, nil - } - paths, err := schema.UIExposedPaths(schemaRow.Data) if err != nil { return nil, errors.WithMessage(err, "read ui-exposed paths") } - s.uiPathsCache.entries[moduleId] = cachedUIPaths{version: schemaRow.ModuleVersion, paths: paths} return paths, nil }