Diffstat (limited to 'internal/mailer')
| -rw-r--r-- | internal/mailer/mailer.go | 33 |
1 files changed, 13 insertions, 20 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) |