MSP-8299 remove cache

This commit is contained in:
ziminis committed 2026-11-30 13:53:34 +07:00
1 parent 251ce269ef
commit fdee70e51e
1 file changed
+13 -36
+13 -36
View File
@@ -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
}