diff --git a/api.go b/api.go index 5123f8afb..a5c6f4202 100644 --- a/api.go +++ b/api.go @@ -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") } diff --git a/txfactory.go b/txfactory.go index 8a2b987cb..f4373658b 100644 --- a/txfactory.go +++ b/txfactory.go @@ -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 {