Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(mailserver)_: reduce debug logs size in messenger_mailserver #5894

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions protocol/messenger_mailserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package protocol

import (
"context"
"crypto/sha256"
"encoding/hex"
"fmt"
"math"
"sort"
Expand Down Expand Up @@ -756,15 +758,15 @@ func processMailserverBatch(
for _, t := range batch.Topics {
topicStrings = append(topicStrings, t.String())
}
logger = logger.With(zap.Any("chatIDs", batch.ChatIDs),
logger = logger.With(zap.String("batch hash", batch.Hash()))
logger.Info("syncing topic",
zap.Any("chatIDs", batch.ChatIDs),
zap.String("fromString", time.Unix(int64(batch.From), 0).Format(time.RFC3339)),
zap.String("toString", time.Unix(int64(batch.To), 0).Format(time.RFC3339)),
zap.Any("topic", topicStrings),
zap.Int64("from", int64(batch.From)),
zap.Int64("to", int64(batch.To)))

logger.Info("syncing topic")

wg := sync.WaitGroup{}
workWg := sync.WaitGroup{}
workCh := make(chan work, 1000) // each batch item is split in 10 topics bunch and sent to this channel
Expand Down Expand Up @@ -959,6 +961,12 @@ type MailserverBatch struct {
ChatIDs []string
}

func (mb *MailserverBatch) Hash() string {
data := fmt.Sprintf("%d%d%s%s%v%v", mb.From, mb.To, mb.Cursor, mb.PubsubTopic, mb.Topics, mb.ChatIDs)
hash := sha256.Sum256([]byte(data))
return hex.EncodeToString(hash[:4])
}

func (m *Messenger) SyncChatFromSyncedFrom(chatID string) (uint32, error) {
chat, ok := m.allChats.Load(chatID)
if !ok {
Expand Down