diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-12-22 18:51:42 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-12-22 18:51:42 +0100 |
| commit | 9ad7b0e67c90697893f188323a32590fbecd5a65 (patch) | |
| tree | 41c8684a652e8fc5dbedb07bdde6404df4afb628 /backend/storage | |
| parent | cbd5c09c5e1403709d4aabf91051443f147689e5 (diff) | |
fix(storage): does not store stats if request fails
Diffstat (limited to 'backend/storage')
| -rw-r--r-- | backend/storage/db.go | 6 | ||||
| -rw-r--r-- | backend/storage/stats.go | 7 |
2 files changed, 6 insertions, 7 deletions
diff --git a/backend/storage/db.go b/backend/storage/db.go index 7a7c6e0..0ee50da 100644 --- a/backend/storage/db.go +++ b/backend/storage/db.go @@ -13,6 +13,8 @@ import ( _ "github.com/mattn/go-sqlite3" ) +const DBKey = "db" + //go:embed migrations var migrations embed.FS @@ -66,3 +68,7 @@ func RunMigration(ctx context.Context, db *sql.DB) error { } return nil } + +func getDB(ctx context.Context) *sql.DB { + return ctx.Value(DBKey).(*sql.DB) +} diff --git a/backend/storage/stats.go b/backend/storage/stats.go index 757168d..d95387d 100644 --- a/backend/storage/stats.go +++ b/backend/storage/stats.go @@ -2,7 +2,6 @@ package storage import ( "context" - "database/sql" "fmt" "log/slog" "net/http" @@ -13,8 +12,6 @@ import ( "time" ) -const DBKey = "db" - type loaded struct { data map[string]struct{} mu *sync.RWMutex @@ -50,10 +47,6 @@ var trimRefererReg = regexp.MustCompile(`https?://([a-z-0-9.]+(:\d+)?)/.*`) var load = newLoaded() -func getDB(ctx context.Context) *sql.DB { - return ctx.Value(DBKey).(*sql.DB) -} - func UpdateStats(ctx context.Context, r *http.Request, domain string) error { target := r.URL.Path if strings.HasPrefix(target, "/static") || strings.HasPrefix(target, "/admin") { |
