Moved Filter.Compile from driver function to datamanager

This commit is contained in:
Trial97
2020-07-09 16:04:12 +03:00
parent 8dda5c97a8
commit 6507aa0f06
2 changed files with 53 additions and 50 deletions

View File

@@ -658,38 +658,40 @@ func (dm *DataManager) GetFilter(tenant, id string, cacheRead, cacheWrite bool,
}
}
if strings.HasPrefix(id, utils.Meta) {
fltr, err = NewFilterFromInline(tenant, id)
if fltr, err = NewFilterFromInline(tenant, id); err != nil {
return
}
} else if dm == nil { // in case we want the filter from dataDB but the connection to dataDB a optional (e.g. SessionS)
err = utils.ErrNoDatabaseConn
return
} else {
fltr, err = dm.DataDB().GetFilterDrv(tenant, id)
}
if err != nil {
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaFilters]; err == utils.ErrNotFound && itm.Remote {
if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, utils.ReplicatorSv1GetFilter,
&utils.TenantIDWithArgDispatcher{
TenantID: &utils.TenantID{Tenant: tenant, ID: id},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer(itm.APIKey),
RouteID: utils.StringPointer(itm.RouteID),
}}, &fltr); err == nil {
err = dm.dataDB.SetFilterDrv(fltr)
}
}
if err != nil {
err = utils.CastRPCErr(err)
if err == utils.ErrNotFound && cacheWrite {
if errCh := Cache.Set(utils.CacheFilters, tntID, nil, nil,
cacheCommit(transactionID), transactionID); errCh != nil {
return nil, errCh
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaFilters]; err == utils.ErrNotFound && itm.Remote {
if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, utils.ReplicatorSv1GetFilter,
&utils.TenantIDWithArgDispatcher{
TenantID: &utils.TenantID{Tenant: tenant, ID: id},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer(itm.APIKey),
RouteID: utils.StringPointer(itm.RouteID),
}}, &fltr); err == nil {
err = dm.dataDB.SetFilterDrv(fltr)
}
}
return
if err != nil {
err = utils.CastRPCErr(err)
if err == utils.ErrNotFound && cacheWrite {
if errCh := Cache.Set(utils.CacheFilters, tntID, nil, nil,
cacheCommit(transactionID), transactionID); errCh != nil {
return nil, errCh
}
}
return
}
}
if err = fltr.Compile(); err != nil { // only compile the value when we get the filter from DB or from remote0
return nil, err
}
}
if err = fltr.Compile(); err != nil {
return nil, err
}
if cacheWrite {
if errCh := Cache.Set(utils.CacheFilters, tntID, fltr, nil,
@@ -2350,41 +2352,42 @@ func (dm *DataManager) GetAttributeProfile(tenant, id string, cacheRead, cacheWr
}
}
if isInline {
attrPrfl, err = NewAttributeFromInline(tenant, id)
if attrPrfl, err = NewAttributeFromInline(tenant, id); err != nil {
return
}
} else if dm == nil {
err = utils.ErrNoDatabaseConn
return
} else {
attrPrfl, err = dm.dataDB.GetAttributeProfileDrv(tenant, id)
}
if err != nil {
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaAttributeProfiles]; err == utils.ErrNotFound && itm.Remote {
if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil,
utils.ReplicatorSv1GetAttributeProfile,
&utils.TenantIDWithArgDispatcher{
TenantID: &utils.TenantID{Tenant: tenant, ID: id},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer(itm.APIKey),
RouteID: utils.StringPointer(itm.RouteID),
}}, &attrPrfl); err == nil {
err = dm.dataDB.SetAttributeProfileDrv(attrPrfl)
if attrPrfl, err = dm.dataDB.GetAttributeProfileDrv(tenant, id); err != nil {
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaAttributeProfiles]; err == utils.ErrNotFound && itm.Remote {
if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil,
utils.ReplicatorSv1GetAttributeProfile,
&utils.TenantIDWithArgDispatcher{
TenantID: &utils.TenantID{Tenant: tenant, ID: id},
ArgDispatcher: &utils.ArgDispatcher{
APIKey: utils.StringPointer(itm.APIKey),
RouteID: utils.StringPointer(itm.RouteID),
}}, &attrPrfl); err == nil {
err = dm.dataDB.SetAttributeProfileDrv(attrPrfl)
}
}
if err != nil {
err = utils.CastRPCErr(err)
if err == utils.ErrNotFound && cacheWrite {
if errCh := Cache.Set(utils.CacheAttributeProfiles, tntID, nil, nil,
cacheCommit(transactionID), transactionID); errCh != nil {
return nil, errCh
}
}
return nil, err
}
}
if err != nil {
err = utils.CastRPCErr(err)
if err == utils.ErrNotFound && cacheWrite {
if errCh := Cache.Set(utils.CacheAttributeProfiles, tntID, nil, nil,
cacheCommit(transactionID), transactionID); errCh != nil {
return nil, errCh
}
}
if err = attrPrfl.Compile(); err != nil {
return nil, err
}
}
if err = attrPrfl.Compile(); err != nil {
return nil, err
}
if cacheWrite {
if errCh := Cache.Set(utils.CacheAttributeProfiles, tntID, attrPrfl, nil,
cacheCommit(transactionID), transactionID); errCh != nil {

View File

@@ -143,7 +143,7 @@ func NewAttributeFromInline(tenant, inlnRule string) (attr *AttributeProfile, er
Tenant: tenant,
ID: inlnRule,
Contexts: []string{utils.META_ANY},
Attributes: []*Attribute{&Attribute{
Attributes: []*Attribute{{
Path: ruleSplt[1],
Type: ruleSplt[0],
Value: vals,