fix(communities): ensure existing archives are seeded on startup

This commit is contained in:
Pascal Precht 2022-09-15 12:15:19 +02:00 committed by r4bbit.eth
parent 9ee2967e78
commit eb4ab9316c
2 changed files with 13 additions and 0 deletions

View File

@ -2096,6 +2096,11 @@ func (m *Manager) LoadHistoryArchiveIndexFromFile(communityID types.HexBytes) (*
return wakuMessageArchiveIndexProto, nil
}
func (m *Manager) TorrentFileExists(communityID string) bool {
_, err := os.Stat(m.torrentFile(communityID))
return err == nil
}
func (m *Manager) torrentFile(communityID string) string {
return m.torrentConfig.TorrentDir + "/" + communityID + ".torrent"
}

View File

@ -1601,6 +1601,14 @@ func (m *Messenger) InitHistoryArchiveTasks(communities []*communities.Community
continue
}
// Check if there's already a torrent file for this community and seed it
if m.communitiesManager.TorrentFileExists(c.IDString()) {
err = m.communitiesManager.SeedHistoryArchiveTorrent(c.ID())
if err != nil {
m.logger.Debug("failed to seed history archive", zap.Error(err))
}
}
filters, err := m.communitiesManager.GetCommunityChatsFilters(c.ID())
if err != nil {
m.logger.Debug("failed to get community chats filters", zap.Error(err))