From a14bb6292bdf26db0b185389ffd599b4925493ae Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 19 Nov 2020 17:50:16 +0300 Subject: [PATCH] [#182] Reuse search filter in policer Signed-off-by: Alex Vanin --- pkg/services/policer/queue.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/services/policer/queue.go b/pkg/services/policer/queue.go index 9c0c1927d7..0b06b51c10 100644 --- a/pkg/services/policer/queue.go +++ b/pkg/services/policer/queue.go @@ -9,16 +9,15 @@ type jobQueue struct { localStorage *localstore.Storage } +var jobFilter object.SearchFilters + func (q *jobQueue) Select(limit int) ([]*object.Address, error) { // TODO: optimize the logic for selecting objects // We can prioritize objects for migration, newly arrived objects, etc. // It is recommended to make changes after updating the metabase - jobFilter := object.NewSearchFilters() - jobFilter.AddPhyFilter() - // FIXME: add the ability to limit Select result - res, err := q.localStorage.Select(jobFilter) + res, err := q.localStorage.Select(getJobFilter()) if err != nil { return nil, err } @@ -29,3 +28,12 @@ func (q *jobQueue) Select(limit int) ([]*object.Address, error) { return res[:limit], nil } + +// getJobFilter is a getter for a singleton instance. +func getJobFilter() object.SearchFilters { + if len(jobFilter) == 0 { + jobFilter.AddPhyFilter() // this initiates a list of filters + } + + return jobFilter +}