Saved Stat
All checks were successful
/ release (push) Successful in 48s

This commit is contained in:
Samuel Lorch 2025-03-19 23:07:11 +01:00
parent e7371850d1
commit a5fc856764
2 changed files with 27 additions and 0 deletions

View file

@ -24,6 +24,7 @@ type StatsDisplay struct {
Size []int
Duration []int
Count []int
Saved []int
}
type ChartData struct {
@ -337,6 +338,14 @@ func handleStats(w http.ResponseWriter, r *http.Request) {
duration = 0
}
var saved int
err = db.QueryRow(r.Context(),
`SELECT (SUM(old_size) - COALESCE(SUM(size), 0)) AS saved
FROM files WHERE ($1 = -1 OR files.library_id = $1) AND status = $2 AND old_size NOT NULL`, id, constants.FILE_STATUS_EXISTS).Scan(&saved)
if err != nil {
saved = 0
}
buf := bytes.Buffer{}
err = templates.ExecuteTemplate(&buf, constants.STATS_TEMPLATE_NAME, StatsDisplay{
Libraries: libraries,
@ -344,6 +353,7 @@ func handleStats(w http.ResponseWriter, r *http.Request) {
Size: splitInt(size),
Count: splitInt(count),
Duration: splitInt(duration),
Saved: splitInt(saved),
Charts: data,
})
if err != nil {