From 334546f8e8913dcbc587e39eae89ecc4c62cf274 Mon Sep 17 00:00:00 2001 From: Patryk Osmaczko Date: Thu, 8 Jun 2023 12:22:26 +0200 Subject: [PATCH] chore: resume archives import with delay closes: status-im/status-desktop#10937 --- protocol/messenger.go | 1 + protocol/messenger_communities.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/protocol/messenger.go b/protocol/messenger.go index 29b479df0e0..9decc344799 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -773,6 +773,7 @@ func (m *Messenger) Start() (*MessengerResponse, error) { return nil, err } } + m.enableHistoryArchivesImportAfterDelay() if m.httpServer != nil { err = m.httpServer.Start() diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index af7f88c7228..e8b7744c3b7 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -50,11 +50,13 @@ var updateActiveMembersInterval = 24 * time.Hour const discordTimestampLayout = "2006-01-02T15:04:05+00:00" var importRateLimiter = rate.NewLimiter(rate.Every(importSlowRate), 1) +var importDelayer = make(chan struct{}) const ( importSlowRate = time.Second / 1 importFastRate = time.Second / 100 importMessagesChunkSize = 10 + importInitialDelay = time.Minute * 5 ) const ( @@ -2334,6 +2336,13 @@ func (m *Messenger) InitHistoryArchiveTasks(communities []*communities.Community } } +func (m *Messenger) enableHistoryArchivesImportAfterDelay() { + go func() { + time.Sleep(importInitialDelay) + close(importDelayer) + }() +} + func (m *Messenger) resumeHistoryArchivesImport(communityID types.HexBytes) error { archiveIDsToImport, err := m.communitiesManager.GetMessageArchiveIDsToImport(communityID) if err != nil { @@ -2391,6 +2400,13 @@ func (m *Messenger) importHistoryArchives(communityID types.HexBytes, cancel cha cancelFunc() }() + // don't proceed until initial import delay has passed + select { + case <-importDelayer: + case <-ctx.Done(): + return nil + } + importMessageArchivesLoop: for { select {