Files
2026-08-15 07:13:00 +00:00

31 lines
1.0 KiB
Go

package store
import "context"
// Counts is the summary behind GET /api/v1/system/info.
type Counts struct {
Projects int64
Deployments int64
Blobs int64
// CASBytes is the size of the blobs the store believes are on disk. It is
// the deduplicated total, so it is smaller — usually much smaller — than the
// sum of the deployments' sizes.
CASBytes int64
}
// Counts gathers the summary in one round trip.
//
// The subqueries are counted separately rather than joined: a join would have
// to fan out over deployment_files and then collapse again, which on a large
// manifest is thousands of times the work for the same four numbers.
func (d *DB) Counts(ctx context.Context) (Counts, error) {
var c Counts
err := d.r.QueryRowContext(ctx, `
SELECT (SELECT count(*) FROM projects),
(SELECT count(*) FROM deployments),
(SELECT count(*) FROM blobs WHERE present = 1),
(SELECT coalesce(sum(size), 0) FROM blobs WHERE present = 1)`).
Scan(&c.Projects, &c.Deployments, &c.Blobs, &c.CASBytes)
return c, err
}