From f5be4377112a8fed848d96214f59ebdb26dbbbeb Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Fri, 8 Aug 2025 21:30:59 +0300 Subject: [PATCH] ips: move ComputeUnexported to DataManager --- engine/datamanager.go | 13 +++++++++---- ips/apis.go | 2 +- ips/ips.go | 6 +----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/engine/datamanager.go b/engine/datamanager.go index 5e59001d2..7874f5b58 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -170,7 +170,7 @@ func (dm *DataManager) CacheDataFromDB(ctx *context.Context, prfx string, ids [] case utils.IPAllocationsPrefix: tntID := utils.NewTenantID(dataID) lkID := guardian.Guardian.GuardIDs("", dm.cfg.GeneralCfg().LockingTimeout, utils.IPAllocationsLockKey(tntID.Tenant, tntID.ID)) - _, err = dm.GetIPAllocations(ctx, tntID.Tenant, tntID.ID, false, true, utils.NonTransactional) + _, err = dm.GetIPAllocations(ctx, tntID.Tenant, tntID.ID, false, true, utils.NonTransactional, nil) guardian.Guardian.UnguardIDs(lkID) case utils.StatQueueProfilePrefix: tntID := utils.NewTenantID(dataID) @@ -1684,7 +1684,7 @@ func (dm *DataManager) RemoveResourceProfile(ctx *context.Context, tenant, id st } func (dm *DataManager) GetIPAllocations(ctx *context.Context, tenant, id string, cacheRead, cacheWrite bool, - transactionID string) (ip *utils.IPAllocations, err error) { + transactionID string, prfl *utils.IPProfile) (ip *utils.IPAllocations, err error) { tntID := utils.ConcatenatedKey(tenant, id) if cacheRead { if x, ok := Cache.Get(utils.CacheIPAllocations, tntID); ok { @@ -1724,6 +1724,11 @@ func (dm *DataManager) GetIPAllocations(ctx *context.Context, tenant, id string, return nil, err } } + if prfl != nil { + if err = ip.ComputeUnexported(prfl); err != nil { + return nil, err + } + } if cacheWrite { if errCh := Cache.Set(ctx, utils.CacheIPAllocations, tntID, ip, nil, cacheCommit(transactionID), transactionID); errCh != nil { @@ -1871,8 +1876,8 @@ func (dm *DataManager) SetIPProfile(ctx *context.Context, ipp *utils.IPProfile, ID: ipp.ID, Allocations: make(map[string]*utils.PoolAllocation), }) - } else if _, errRs := dm.GetIPAllocations(ctx, ipp.Tenant, ipp.ID, // do not try to get the resource if the configuration changed - true, false, utils.NonTransactional); errRs == utils.ErrNotFound { // the resource does not exist + } else if _, errGet := dm.GetIPAllocations(ctx, ipp.Tenant, ipp.ID, // do not try to get the resource if the configuration changed + true, false, utils.NonTransactional, nil); errGet == utils.ErrNotFound { // the resource does not exist err = dm.SetIPAllocations(ctx, &utils.IPAllocations{ Tenant: ipp.Tenant, ID: ipp.ID, diff --git a/ips/apis.go b/ips/apis.go index 4558f518a..dba07dd63 100644 --- a/ips/apis.go +++ b/ips/apis.go @@ -291,7 +291,7 @@ func (s *IPService) V1GetIPAllocations(ctx *context.Context, arg *utils.TenantID utils.IPAllocationsLockKey(tnt, arg.ID)) defer guardian.Guardian.UnguardIDs(lkID) - ip, err := s.dm.GetIPAllocations(ctx, tnt, arg.ID, true, true, utils.NonTransactional) + ip, err := s.dm.GetIPAllocations(ctx, tnt, arg.ID, true, true, utils.NonTransactional, nil) if err != nil { return err } diff --git a/ips/ips.go b/ips/ips.go index 67d84fab2..fc9ee90d1 100644 --- a/ips/ips.go +++ b/ips/ips.go @@ -260,17 +260,13 @@ func (s *IPService) matchingIPAllocationsForEvent(ctx *context.Context, tnt stri lkID := guardian.Guardian.GuardIDs(utils.EmptyString, config.CgrConfig().GeneralCfg().LockingTimeout, utils.IPAllocationsLockKey(matchedPrfl.Tenant, matchedPrfl.ID)) - allocs, err = s.dm.GetIPAllocations(ctx, matchedPrfl.Tenant, matchedPrfl.ID, true, true, "") + allocs, err = s.dm.GetIPAllocations(ctx, matchedPrfl.Tenant, matchedPrfl.ID, true, true, "", matchedPrfl) if err != nil { guardian.Guardian.UnguardIDs(lkID) matchedPrfl.Unlock() return nil, err } allocs.Lock(lkID) - if err = allocs.ComputeUnexported(matchedPrfl); err != nil { - allocs.Unlock() - return nil, err - } if err = engine.Cache.Set(ctx, utils.CacheEventIPs, evUUID, // TODO: check if we still should rely on caching previously matched