storagenode/consoledb: fix daily bandwidth query (#2446)

* storagenode/consoledb fix daily bandwidth query
This commit is contained in:
Yaroslav Vorobiov 2019-07-03 22:08:40 +03:00 committed by Bill Thorp
parent 56fcf228fb
commit 5557d557f9

View File

@ -6,7 +6,6 @@ package storagenodedb
import (
"context"
"database/sql"
"strings"
"time"
"github.com/zeebo/errs"
@ -89,16 +88,15 @@ func (db *consoledb) GetDailyBandwidthUsed(ctx context.Context, satelliteID stor
func (db *consoledb) getDailyBandwidthUsed(ctx context.Context, cond string, args ...interface{}) (_ []console.BandwidthUsed, err error) {
defer mon.Task()(&ctx)(&err)
qb := strings.Builder{}
qb.WriteString("SELECT action, SUM(amount), created_at ")
qb.WriteString("FROM bandwidth_usage ")
if cond != "" {
qb.WriteString(cond + " ")
}
qb.WriteString("GROUP BY DATE(created_at), action ")
qb.WriteString("ORDER BY created_at ASC")
query := db.Rebind(`
SELECT action, SUM(amount), created_at
FROM bandwidth_usage
` + cond + `
GROUP BY DATE(created_at), action
ORDER BY created_at ASC
`)
rows, err := db.db.QueryContext(ctx, db.Rebind(qb.String()), args)
rows, err := db.db.QueryContext(ctx, query, args...)
if err != nil {
return nil, err
}