Skip to content

Commit

Permalink
Remove sync.OnceFunc usage. Fixes #679
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Dec 28, 2023
1 parent cb6afe2 commit 4efb226
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions historysync.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/base64"
"fmt"
"strings"
"sync"
"time"

"github.com/rs/zerolog"
Expand Down Expand Up @@ -458,8 +457,12 @@ func (user *User) storeHistorySync(evt *waProto.HistorySync) {
Int("msg_count", len(conv.GetMessages())).
Logger()

initPortal := sync.OnceFunc(func() {
portal := user.GetPortalByJID(jid)
var portal *Portal
initPortal := func() {
if portal != nil {
return
}
portal = user.GetPortalByJID(jid)
historySyncConversation := user.bridge.DB.HistorySync.NewConversationWithValues(
user.MXID,
conv.GetId(),
Expand All @@ -474,7 +477,7 @@ func (user *User) storeHistorySync(evt *waProto.HistorySync) {
conv.GetMarkedAsUnread(),
conv.GetUnreadCount())
historySyncConversation.Upsert()
})
}

var minTime, maxTime time.Time
var minTimeIndex, maxTimeIndex int
Expand Down

0 comments on commit 4efb226

Please sign in to comment.