satellitedb/accounting: fixed query (#3672)
This commit is contained in:
parent
d9a23b8727
commit
ae05fa0874
@ -252,11 +252,9 @@ func (db *ProjectAccounting) GetProjectTotal(ctx context.Context, projectID uuid
|
|||||||
|
|
||||||
bucketsTallies := make(map[string][]*accounting.BucketStorageTally)
|
bucketsTallies := make(map[string][]*accounting.BucketStorageTally)
|
||||||
|
|
||||||
var storageTalliesRows *sql.Rows = nil
|
|
||||||
|
|
||||||
for _, bucket := range bucketNames {
|
for _, bucket := range bucketNames {
|
||||||
storageTallies := make([]*accounting.BucketStorageTally, 0)
|
storageTallies := make([]*accounting.BucketStorageTally, 0)
|
||||||
storageTalliesRows, err = db.db.QueryContext(ctx, storageQuery, projectID[:], []byte(bucket), since, before)
|
storageTalliesRows, err := db.db.QueryContext(ctx, storageQuery, projectID[:], []byte(bucket), since, before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -273,11 +271,14 @@ func (db *ProjectAccounting) GetProjectTotal(ctx context.Context, projectID uuid
|
|||||||
storageTallies = append(storageTallies, &tally)
|
storageTallies = append(storageTallies, &tally)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = storageTalliesRows.Close()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
bucketsTallies[bucket] = storageTallies
|
bucketsTallies[bucket] = storageTallies
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() { err = errs.Combine(err, storageTalliesRows.Close()) }()
|
|
||||||
|
|
||||||
totalEgress, err := db.getTotalEgress(ctx, projectID, since, before)
|
totalEgress, err := db.getTotalEgress(ctx, projectID, since, before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -310,7 +311,7 @@ func (db *ProjectAccounting) GetProjectTotal(ctx context.Context, projectID uuid
|
|||||||
func (db *ProjectAccounting) getTotalEgress(ctx context.Context, projectID uuid.UUID, since, before time.Time) (totalEgress int64, err error) {
|
func (db *ProjectAccounting) getTotalEgress(ctx context.Context, projectID uuid.UUID, since, before time.Time) (totalEgress int64, err error) {
|
||||||
totalEgressQuery := db.db.Rebind(fmt.Sprintf(`
|
totalEgressQuery := db.db.Rebind(fmt.Sprintf(`
|
||||||
SELECT
|
SELECT
|
||||||
SUM(settled) + SUM(inline)
|
COALESCE(SUM(settled) + SUM(inline), 0)
|
||||||
FROM
|
FROM
|
||||||
bucket_bandwidth_rollups
|
bucket_bandwidth_rollups
|
||||||
WHERE
|
WHERE
|
||||||
|
Loading…
Reference in New Issue
Block a user