mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-13 02:56:24 +05:00
ResourceS with indexedFields for faster queries on string indexes
This commit is contained in:
@@ -541,7 +541,7 @@ func startResourceService(internalRsChan, internalThresholdSChan chan rpcclient.
|
||||
return
|
||||
}
|
||||
}
|
||||
rS, err := engine.NewResourceService(dm, cfg.ResourceSCfg().StoreInterval, thdSConn, filterS)
|
||||
rS, err := engine.NewResourceService(dm, cfg.ResourceSCfg().StoreInterval, thdSConn, filterS, cfg.ResourceSCfg().IndexedFields)
|
||||
if err != nil {
|
||||
utils.Logger.Crit(fmt.Sprintf("<ResourceS> Could not init, error: %s", err.Error()))
|
||||
exitChan <- true
|
||||
|
||||
@@ -279,7 +279,7 @@ func (rs Resources) allocateResource(ru *ResourceUsage, dryRun bool) (alcMessage
|
||||
|
||||
// Pas the config as a whole so we can ask access concurrently
|
||||
func NewResourceService(dm *DataManager, storeInterval time.Duration,
|
||||
thdS rpcclient.RpcClientConnection, filterS *FilterS) (*ResourceService, error) {
|
||||
thdS rpcclient.RpcClientConnection, filterS *FilterS, indexedFields []string) (*ResourceService, error) {
|
||||
if thdS != nil && reflect.ValueOf(thdS).IsNil() {
|
||||
thdS = nil
|
||||
}
|
||||
@@ -296,6 +296,7 @@ type ResourceService struct {
|
||||
dm *DataManager // So we can load the data in cache and index it
|
||||
thdS rpcclient.RpcClientConnection // allows applying filters based on stats
|
||||
filterS *FilterS
|
||||
indexedFields []string // speed up query on indexes
|
||||
lcEventResources map[string][]*utils.TenantID // cache recording resources for events in alocation phase
|
||||
lcERMux sync.RWMutex // protects the lcEventResources
|
||||
storedResources utils.StringMap // keep a record of resources which need saving, map[resID]bool
|
||||
@@ -433,7 +434,7 @@ func (rS *ResourceService) cachedResourcesForEvent(evUUID string) (rs Resources)
|
||||
// matchingResourcesForEvent returns ordered list of matching resources which are active by the time of the call
|
||||
func (rS *ResourceService) matchingResourcesForEvent(tenant string, ev map[string]interface{}) (rs Resources, err error) {
|
||||
matchingResources := make(map[string]*Resource)
|
||||
rIDs, err := matchingItemIDsForEvent(ev, nil, rS.dm, utils.ResourceProfilesStringIndex+tenant)
|
||||
rIDs, err := matchingItemIDsForEvent(ev, rS.indexedFields, rS.dm, utils.ResourceProfilesStringIndex+tenant)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user