diff options
| author | 2025-10-25 23:25:31 +0700 | |
|---|---|---|
| committer | 2025-10-25 23:25:31 +0700 | |
| commit | dd69b45d3a41be2b5c38892c3b107770a0f859f2 (patch) | |
| tree | d2b6ed2bd645eef448f987e57b97ff918909ea48 /internal/router/client-cache.go | |
| parent | 69b868a7655a25c82ce4a2bd444812be69c8b998 (diff) | |
| parent | 629e275e5270ed146f9cd6dba25383cf80022909 (diff) | |
| download | web-dd69b45d3a41be2b5c38892c3b107770a0f859f2.tar.gz web-dd69b45d3a41be2b5c38892c3b107770a0f859f2.zip | |
v0.11.0 (#17)v0.11.0
- [feat: send new blog posts to
subscribers](https://github.com/SayaAndy/saya-today-web/commit/adcd8cf82f7ec4027701643c545b1f27a7cfc221)
- [feat: email
linking](https://github.com/SayaAndy/saya-today-web/commit/0d261d2f7d080b610f50102576073e334a89e8cb)
- [feat: subscription
settings](https://github.com/SayaAndy/saya-today-web/commit/4b2da2abbc7376ce0de71a00b18b7091b00dbcd1)
- [feat: allow to unsubscribe from an
email](https://github.com/SayaAndy/saya-today-web/commit/df7a0ae1c0fc177cba2eae8cc73fe21d2afdd229)
Diffstat (limited to 'internal/router/client-cache.go')
| -rw-r--r-- | internal/router/client-cache.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/internal/router/client-cache.go b/internal/router/client-cache.go index d607cdd..e7cda30 100644 --- a/internal/router/client-cache.go +++ b/internal/router/client-cache.go @@ -31,10 +31,12 @@ func NewClientCache(db *sql.DB, salt []byte) (*ClientCache, error) { if err != nil { return nil, fmt.Errorf("fail to init transaction with db to fill cache: %w", err) } + slog.Debug("began db transaction", slog.String("method", "NewClientCache")) rows, err := tx.Query("select * from blog_likes;") if err != nil { tx.Rollback() + slog.Debug("ended db transaction", slog.String("method", "NewClientCache")) return nil, fmt.Errorf("fail to query db for blog_likes to fill cache: %w", err) } @@ -62,6 +64,7 @@ func NewClientCache(db *sql.DB, salt []byte) (*ClientCache, error) { rows, err = tx.Query("select * from blog_views;") if err != nil { tx.Rollback() + slog.Debug("ended db transaction", slog.String("method", "NewClientCache")) return nil, fmt.Errorf("fail to query db for blog_views to fill cache: %w", err) } @@ -81,8 +84,11 @@ func NewClientCache(db *sql.DB, salt []byte) (*ClientCache, error) { } if err = tx.Commit(); err != nil { + tx.Rollback() + slog.Debug("ended db transaction", slog.String("method", "NewClientCache")) return nil, fmt.Errorf("fail to commit transaction in db: %w", err) } + slog.Debug("ended db transaction", slog.String("method", "NewClientCache")) return &ClientCache{ hashMap: make(map[string]string), @@ -99,18 +105,28 @@ func (c *ClientCache) Close() error { if err != nil { return fmt.Errorf("fail to init transaction with db to dump cache: %w", err) } + slog.Debug("began db transaction in ClientCache.Close") if err = batchSave(tx, "blog_likes", c.likePageMap); err != nil { tx.Rollback() + slog.Debug("ended db transaction in ClientCache.Close") return fmt.Errorf("fail to save blog_likes: %s", err) } if err = batchSave(tx, "blog_views", c.viewPageMap); err != nil { tx.Rollback() + slog.Debug("ended db transaction in ClientCache.Close") return fmt.Errorf("fail to save blog_views: %s", err) } - return tx.Commit() + if err = tx.Commit(); err != nil { + tx.Rollback() + slog.Debug("ended db transaction in ClientCache.Close") + return fmt.Errorf("fail to commit all the changes related to cache: %s", err) + } + + slog.Debug("ended db transaction in ClientCache.Close") + return nil } func (c *ClientCache) GetHash(id string) string { |