summaryrefslogtreecommitdiffci
diff refs
from: back
to: back
| flip
diff options
context:
space:
mode:
-rw-r--r--config/config.local.yaml3
-rw-r--r--internal/mailer/mailer.go22
-rw-r--r--internal/router/client-cache.go12
3 files changed, 1 insertions, 36 deletions
diff --git a/config/config.local.yaml b/config/config.local.yaml
index e23c808..327bad4 100644
--- a/config/config.local.yaml
+++ b/config/config.local.yaml
@@ -32,8 +32,7 @@ auth:
db:
type: sqlite3
config:
- # dsn: 'file:/tmp/auth.db?cache=shared&mode=rwc&_journal_mode=WAL'
- dsn: 'file:/tmp/auth.db?cache=private&mode=rwc&_locking_mode=EXCLUSIVE&_mutex=no&_auto_vacuum=2&_journal_mode=WAL'
+ dsn: 'file:/tmp/auth.db?cache=shared&mode=rwc&_journal_mode=WAL'
salt: '123'
mail:
clientHost: '127.0.0.1:3000'
diff --git a/internal/mailer/mailer.go b/internal/mailer/mailer.go
index 847ebde..eb86d56 100644
--- a/internal/mailer/mailer.go
+++ b/internal/mailer/mailer.go
@@ -151,19 +151,15 @@ func (m *Mailer) MailIsTaken(email string) (bool, error) {
if err != nil {
return false, fmt.Errorf("failed to initialize transaction with db: %s", err)
}
-
- slog.Debug("began db transaction", slog.String("method", "MailIsTaken"))
defer func(tx *sql.Tx) {
if err = tx.Commit(); err != nil {
tx.Rollback()
}
- slog.Debug("ended db transaction", slog.String("method", "MailIsTaken"))
}(tx)
var rows *sql.Rows
if rows, err = tx.Query(`SELECT email FROM user_email_table WHERE email=? LIMIT 1;`, email); err != nil {
tx.Rollback()
-
return false, fmt.Errorf("failed to query user-email settings in db: %s", err)
}
defer rows.Close()
@@ -177,13 +173,10 @@ func (m *Mailer) GetInfo(userIdHash []byte) (email string, lang string, err erro
if err != nil {
return "", "", fmt.Errorf("failed to initialize transaction with db: %s", err)
}
-
- slog.Debug("began db transaction", slog.String("method", "GetInfo"))
defer func(tx *sql.Tx) {
if err = tx.Commit(); err != nil {
tx.Rollback()
}
- slog.Debug("ended db transaction", slog.String("method", "GetInfo"))
}(tx)
var rows *sql.Rows
@@ -317,22 +310,18 @@ func (m *Mailer) Verify(verificationCodeEncoded string, lang string) error {
return fmt.Errorf("failed to initialize transaction with db: %s", err)
}
- slog.Debug("began db transaction", slog.String("method", "Verify"))
if _, err = tx.Exec(`INSERT INTO user_email_table(user_id, email, lang) VALUES(?, ?, ?)
ON CONFLICT(user_id) DO UPDATE SET
email=excluded.email,
lang=excluded.lang;`, m.GetHash(string(userId)), address, lang); err != nil {
tx.Rollback()
- slog.Debug("ended db transaction", slog.String("method", "Verify"))
return fmt.Errorf("failed to configure user-email settings in db: %s", err)
}
if err = tx.Commit(); err != nil {
tx.Rollback()
- slog.Debug("ended db transaction", slog.String("method", "Verify"))
return fmt.Errorf("failed to commit transaction to db: %s", err)
}
- slog.Debug("ended db transaction", slog.String("method", "Verify"))
m.verificationCodes.Del(verificationCode)
delete(m.lostMailMap, verificationSegments[0])
@@ -344,12 +333,9 @@ func (m *Mailer) GetSubscriptions(userId string) (subscriptionType SubscriptionT
if err != nil {
return None, nil, fmt.Errorf("failed to initialize transaction with db: %s", err)
}
-
- slog.Debug("began db transaction", slog.String("method", "GetSubscriptions"))
defer func(tx *sql.Tx) {
if err = tx.Commit(); err != nil {
tx.Rollback()
- slog.Debug("ended db transaction", slog.String("method", "GetSubscriptions"))
}
}(tx)
@@ -387,8 +373,6 @@ func (m *Mailer) Subscribe(userIdHash []byte, subscriptionType SubscriptionType,
return fmt.Errorf("failed to initialize transaction with db: %s", err)
}
- slog.Debug("began db transaction", slog.String("method", "Subscribe"))
-
slices.Sort(tags)
tagsOutput := ""
switch subscriptionType {
@@ -404,16 +388,13 @@ func (m *Mailer) Subscribe(userIdHash []byte, subscriptionType SubscriptionType,
ON CONFLICT(user_id) DO UPDATE SET
tags=excluded.tags;`, userIdHash, tagsOutput); err != nil {
tx.Rollback()
- slog.Debug("ended db transaction", slog.String("method", "Subscribe"))
return fmt.Errorf("failed to configure user-to-tags table in db for the user: %s", err)
}
if err = tx.Commit(); err != nil {
tx.Rollback()
- slog.Debug("ended db transaction", slog.String("method", "Subscribe"))
return fmt.Errorf("failed to commit transaction to db: %s", err)
}
- slog.Debug("ended db transaction", slog.String("method", "Subscribe"))
return nil
}
@@ -424,11 +405,9 @@ func (m *Mailer) NewPost(post *b2.BlogPage) error {
return fmt.Errorf("failed to initialize transaction with db: %s", err)
}
- slog.Debug("began db transaction", slog.String("method", "NewPost"))
var rows *sql.Rows
if rows, err = tx.Query(`SELECT user_id, tags FROM subscription_user_to_tags_table;`); err != nil {
tx.Rollback()
- slog.Debug("ended db transaction", slog.String("method", "NewPost"))
return fmt.Errorf("failed to query user-to-tags table in db: %s", err)
}
@@ -484,7 +463,6 @@ rowLoop:
tx.Commit()
rows.Close()
- slog.Debug("ended db transaction", slog.String("method", "NewPost"))
messages := make([]*mail.Msg, 0, len(usersToSend))
for _, user := range usersToSend {
diff --git a/internal/router/client-cache.go b/internal/router/client-cache.go
index e7cda30..26557d0 100644
--- a/internal/router/client-cache.go
+++ b/internal/router/client-cache.go
@@ -31,12 +31,10 @@ 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)
}
@@ -64,7 +62,6 @@ 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)
}
@@ -84,11 +81,8 @@ 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),
@@ -105,27 +99,21 @@ 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)
}
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
}