From 15a960da19cc3c5d0252a32f705dc453a2f40f95 Mon Sep 17 00:00:00 2001 From: Samuel Lorch Date: Wed, 19 Mar 2025 23:13:08 +0100 Subject: [PATCH] fix sql, counter show 0 --- server/index.go | 4 ++++ server/stats.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/server/index.go b/server/index.go index a23c9c5..f72a04f 100644 --- a/server/index.go +++ b/server/index.go @@ -91,6 +91,10 @@ func handleIndex(w http.ResponseWriter, r *http.Request) { } func splitInt(n int) []int { + if n == 0 { + return []int{0} + } + slc := []int{} for n > 0 { slc = append(slc, n%10) diff --git a/server/stats.go b/server/stats.go index 2b1ca0f..49cd360 100644 --- a/server/stats.go +++ b/server/stats.go @@ -341,7 +341,7 @@ func handleStats(w http.ResponseWriter, r *http.Request) { 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) + FROM files WHERE ($1 = -1 OR files.library_id = $1) AND status = $2 AND old_size IS NOT NULL`, id, constants.FILE_STATUS_EXISTS).Scan(&saved) if err != nil { saved = 0 }