| -rw-r--r-- | internal/mailer/mailer.go | 33 | ||||
| -rw-r--r-- | internal/router/lang-user-unsubscribe.go | 2 |
2 files changed, 13 insertions, 22 deletions
diff --git a/internal/mailer/mailer.go b/internal/mailer/mailer.go index d6dbd17..847ebde 100644 --- a/internal/mailer/mailer.go +++ b/internal/mailer/mailer.go @@ -349,8 +349,8 @@ func (m *Mailer) GetSubscriptions(userId string) (subscriptionType SubscriptionT defer func(tx *sql.Tx) { if err = tx.Commit(); err != nil { tx.Rollback() + slog.Debug("ended db transaction", slog.String("method", "GetSubscriptions")) } - slog.Debug("ended db transaction", slog.String("method", "GetSubscriptions")) }(tx) hash := m.GetHash(userId) @@ -452,11 +452,21 @@ rowLoop: continue } + email, lang, err := m.GetInfo(userId) + if err != nil { + slog.Warn("failed to get info about the user", slog.String("error", err.Error()), slog.Int("index", i), slog.String("user_id", base64.RawStdEncoding.EncodeToString(userId))) + continue + } + + if lang != post.Lang { + continue + } + if tagsString == "_all" { usersToSend = append(usersToSend, struct { userId []byte email string - }{userId, ""}) + }{userId, email}) continue } @@ -466,7 +476,7 @@ rowLoop: usersToSend = append(usersToSend, struct { userId []byte email string - }{userId, ""}) + }{userId, email}) continue rowLoop } } @@ -476,25 +486,8 @@ rowLoop: rows.Close() slog.Debug("ended db transaction", slog.String("method", "NewPost")) - for i := range usersToSend { - email, lang, err := m.GetInfo(usersToSend[i].userId) - if err != nil { - slog.Warn("failed to get info about the user", slog.String("error", err.Error()), slog.Int("index", i), slog.String("user_id", base64.RawStdEncoding.EncodeToString(userId))) - continue - } - - if lang != post.Lang { - continue - } - - usersToSend[i].email = email - } - messages := make([]*mail.Msg, 0, len(usersToSend)) for _, user := range usersToSend { - if user.email == "" { - continue - } unsubscribeCodeBytes := make([]byte, 8) rand.Read(unsubscribeCodeBytes) unsubscribeCode := binary.LittleEndian.Uint64(unsubscribeCodeBytes) diff --git a/internal/router/lang-user-unsubscribe.go b/internal/router/lang-user-unsubscribe.go index c39f5e7..81d1bfb 100644 --- a/internal/router/lang-user-unsubscribe.go +++ b/internal/router/lang-user-unsubscribe.go @@ -35,13 +35,11 @@ func Lang_User_Unsubscribe(l map[string]*locale.LocaleConfig, langs []config.Ava statusText = l[lang].UnsubscribePage.UnsetCode status = fiber.ErrBadRequest.Code } else if clientError, serverError := Mailer.Unsubscribe(unsubscribeCode); clientError != nil { - slog.Info("got a client error when unsubscribing", slog.String("error", clientError.Error())) statusColor = "255, 0, 0" statusEmoji = "(͠≖~≖ ͡ )" statusText = l[lang].UnsubscribePage.InvalidCode status = fiber.ErrBadRequest.Code } else if serverError != nil { - slog.Error("got a server error when unsubscribing", slog.String("error", serverError.Error())) statusColor = "255, 128, 0" statusEmoji = "( ˶°ㅁ°) !!" statusText = l[lang].UnsubscribePage.OnServerError |