add cache

This commit is contained in:
Samir Patel 2021-05-20 11:57:43 -05:00 • committed by Samir Patel
parent 3c399bc533
commit c812cca58e
2 changed files with 7 additions and 3 deletions

8
api.go
View file

@ -59,6 +59,8 @@ type API struct {
importWorkerPoolSize int
importWork chan importJob
usageCache map[string]NodeUsage
Serializer Serializer
}
@ -934,9 +936,11 @@ func (api *API) Usage(ctx context.Context, remote bool) (map[string]NodeUsage, e
span, _ := tracing.StartSpanFromContext(ctx, "API.Usage")
defer span.Finish()
nodeUsages := make(map[string]NodeUsage)
if api.usageCache == nil {
api.usageCache = make(map[string]NodeUsage)
}
indexDetails, nodeMetadataBytes, err := api.holder.Txf().IndexUsageDetails()
indexDetails, nodeMetadataBytes, err := api.holder.Txf().IndexUsageDetails(api.usageCache[api.server.nodeID].Disk.IndexUsage)
if err != nil {
return nil, errors.Wrap(err, "getting node usage")
}

View file

@ -572,7 +572,7 @@ func (f *TxFactory) DumpAll() {
// IndexUsageDetails computes the sum of filesizes used by the node, broken down
// by index, field, fragments and keys.
func (f *TxFactory) IndexUsageDetails() (map[string]IndexUsage, uint64, error) {
func (f *TxFactory) IndexUsageDetails(cache *map[string]IndexUsage) (map[string]IndexUsage, uint64, error) {
indexUsage := make(map[string]IndexUsage)
holderPath, err := expandDirName(f.holder.path)
if err != nil {