mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Moved Filter.Compile from driver function to datamanager
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -12,6 +12,7 @@ dean*
|
||||
data/vagrant/.vagrant
|
||||
data/vagrant/vagrant_ansible_inventory_default
|
||||
data/tutorials/fs_evsock/freeswitch/etc/freeswitch/
|
||||
data/tutorials/sip_redirect/freeswitch/etc/freeswitch/
|
||||
data/tutorial_tests/fs_evsock/freeswitch/etc/freeswitch/
|
||||
vendor
|
||||
*.test
|
||||
|
||||
@@ -541,27 +541,31 @@ func GetFilter(dm *DataManager, 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 err == utils.ErrNotFound &&
|
||||
config.CgrConfig().DataDbCfg().Items[utils.MetaFilters].Remote {
|
||||
if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, utils.ReplicatorSv1GetFilter,
|
||||
&utils.TenantID{Tenant: tenant, ID: id}, &fltr); err == nil {
|
||||
err = dm.dataDB.SetFilterDrv(fltr)
|
||||
if fltr, err = dm.DataDB().GetFilterDrv(tenant, id); err != nil {
|
||||
if err == utils.ErrNotFound &&
|
||||
config.CgrConfig().DataDbCfg().Items[utils.MetaFilters].Remote {
|
||||
if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, utils.ReplicatorSv1GetFilter,
|
||||
&utils.TenantID{Tenant: tenant, ID: id}, &fltr); err == nil {
|
||||
err = dm.dataDB.SetFilterDrv(fltr)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
Cache.Set(utils.CacheFilters, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
Cache.Set(utils.CacheFilters, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID)
|
||||
}
|
||||
if err = fltr.Compile(); err != nil { // only compile the value when we get the filter from DB or from remote
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -1813,35 +1817,36 @@ 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 err == utils.ErrNotFound &&
|
||||
config.CgrConfig().DataDbCfg().Items[utils.MetaAttributeProfiles].Remote {
|
||||
if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil,
|
||||
utils.ReplicatorSv1GetAttributeProfile,
|
||||
&utils.TenantID{Tenant: tenant, ID: id}, &attrPrfl); err == nil {
|
||||
err = dm.dataDB.SetAttributeProfileDrv(attrPrfl)
|
||||
if attrPrfl, err = dm.dataDB.GetAttributeProfileDrv(tenant, id); err != nil {
|
||||
if err == utils.ErrNotFound &&
|
||||
config.CgrConfig().DataDbCfg().Items[utils.MetaAttributeProfiles].Remote {
|
||||
if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil,
|
||||
utils.ReplicatorSv1GetAttributeProfile,
|
||||
&utils.TenantID{Tenant: tenant, ID: id}, &attrPrfl); err == nil {
|
||||
err = dm.dataDB.SetAttributeProfileDrv(attrPrfl)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
Cache.Set(utils.CacheAttributeProfiles, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID)
|
||||
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
err = utils.CastRPCErr(err)
|
||||
if err == utils.ErrNotFound && cacheWrite {
|
||||
Cache.Set(utils.CacheAttributeProfiles, tntID, nil, nil,
|
||||
cacheCommit(transactionID), transactionID)
|
||||
|
||||
}
|
||||
if err = attrPrfl.Compile(); err != nil { // only compile the value when we get the attribute from DB or from remote
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err = attrPrfl.Compile(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cacheWrite {
|
||||
Cache.Set(utils.CacheAttributeProfiles, tntID, attrPrfl, nil,
|
||||
cacheCommit(transactionID), transactionID)
|
||||
|
||||
@@ -137,7 +137,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,
|
||||
|
||||
@@ -2052,11 +2052,6 @@ func (ms *MongoStorage) GetFilterDrv(tenant, id string) (r *Filter, err error) {
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, fltr := range r.Rules {
|
||||
if err = fltr.CompileValues(); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1469,11 +1469,6 @@ func (rs *RedisStorage) GetFilterDrv(tenant, id string) (r *Filter, err error) {
|
||||
if err = rs.ms.Unmarshal(values, &r); err != nil {
|
||||
return
|
||||
}
|
||||
for _, fltr := range r.Rules {
|
||||
if err = fltr.CompileValues(); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user