From c33d3b275f2580bff2d510715448c14be1d5d5b5 Mon Sep 17 00:00:00 2001 From: SayaAndy Date: Sat, 30 Aug 2025 13:58:46 +0700 Subject: fix: truncate likes table prior to dumping cache --- internal/router/client-cache.go | 5 +++++ main.go | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/router/client-cache.go b/internal/router/client-cache.go index 56cd595..b930d5a 100644 --- a/internal/router/client-cache.go +++ b/internal/router/client-cache.go @@ -76,6 +76,11 @@ func (c *ClientCache) Close() error { return fmt.Errorf("fail to init transaction with db to dump cache: %w", err) } + if _, err = tx.Exec("delete from blog_likes;"); err != nil { + tx.Rollback() + return fmt.Errorf("fail to truncate table blog_likes: %w", err) + } + userIdBytes := make(map[string][]byte) sqlStatement := fmt.Sprintf(` diff --git a/main.go b/main.go index 2f08ba6..020f8ef 100644 --- a/main.go +++ b/main.go @@ -143,7 +143,14 @@ func main() { <-sigChan slog.Info("gracefully shutting down...") - app.Shutdown() - router.CCache.Close() + if err = app.Shutdown(); err != nil { + slog.Error("fail to shutdown fiber server", slog.String("error", err.Error())) + } + if err = router.CCache.Close(); err != nil { + slog.Error("fail to dump cache", slog.String("error", err.Error())) + } + if err = db.Close(); err != nil { + slog.Error("fail to close db connection", slog.String("error", err.Error())) + } db.Close() } -- cgit v1.3.1+13