From d4f7a2bc99ac11b56d9b6c30204e19576b29a6ee Mon Sep 17 00:00:00 2001 From: Yaron de Leeuw Date: Thu, 27 Apr 2017 02:51:43 -0400 Subject: [PATCH] minor code style: use `strings.Replace` fourth argument in influxdb (#8225) Remove 5 lines from the codebase and an unecessary function, by calling `strings.Replace` with -1 for the fourth argument. A better alternative to what was merged in #8037 --- pkg/tsdb/influxdb/query.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/pkg/tsdb/influxdb/query.go b/pkg/tsdb/influxdb/query.go index 19f374b938b..f271c5d245f 100644 --- a/pkg/tsdb/influxdb/query.go +++ b/pkg/tsdb/influxdb/query.go @@ -34,18 +34,13 @@ func (query *Query) Build(queryContext *tsdb.QueryContext) (string, error) { return "", err } - res = replaceVariable(res, "$timeFilter", query.renderTimeFilter(queryContext)) - res = replaceVariable(res, "$interval", interval.Text) - res = replaceVariable(res, "$__interval_ms", strconv.FormatInt(interval.Value.Nanoseconds()/int64(time.Millisecond), 10)) - res = replaceVariable(res, "$__interval", interval.Text) + res = strings.Replace(res, "$timeFilter", query.renderTimeFilter(queryContext), -1) + res = strings.Replace(res, "$interval", interval.Text, -1) + res = strings.Replace(res, "$__interval_ms", strconv.FormatInt(interval.Value.Nanoseconds()/int64(time.Millisecond), 10), -1) + res = strings.Replace(res, "$__interval", interval.Text, -1) return res, nil } -func replaceVariable(str string, variable string, value string) string { - count := strings.Count(str, variable) - return strings.Replace(str, variable, value, count) -} - func getDefinedInterval(query *Query, queryContext *tsdb.QueryContext) (*tsdb.Interval, error) { defaultInterval := tsdb.CalculateInterval(queryContext.TimeRange)