From 4efb2260459cfd74a863f7b9b71178873c1fc978 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 28 Dec 2023 17:13:16 +0100 Subject: [PATCH] Remove sync.OnceFunc usage. Fixes #679 --- historysync.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/historysync.go b/historysync.go index 332f922..4adb14e 100644 --- a/historysync.go +++ b/historysync.go @@ -21,7 +21,6 @@ import ( "encoding/base64" "fmt" "strings" - "sync" "time" "github.com/rs/zerolog" @@ -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(), @@ -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