historysync: only save when backfill is enabled

This commit is contained in:
Sumner Evans 2022-04-06 09:00:48 -06:00
parent c664e5f107
commit 78c6d57299
No known key found for this signature in database
GPG key ID: 8904527AB50022FD
2 changed files with 30 additions and 24 deletions

View file

@ -43,8 +43,11 @@ type wrappedInfo struct {
}
func (user *User) handleHistorySyncsLoop() {
if !user.bridge.Config.Bridge.HistorySync.Backfill {
return
}
reCheckQueue := make(chan bool, 1)
if user.bridge.Config.Bridge.HistorySync.Backfill {
// Start the backfill queue.
user.BackfillQueue = &BackfillQueue{
BackfillQuery: user.bridge.DB.BackfillQuery,
@ -65,7 +68,6 @@ func (user *User) handleHistorySyncsLoop() {
// to be more or less aggressive with backfilling at this stage.
go user.handleBackfillRequestsLoop(user.BackfillQueue.DeferredBackfillRequests)
go user.BackfillQueue.RunLoops(user)
}
// Always save the history syncs for the user. If they want to enable
// backfilling in the future, we will have it in the database.

View file

@ -188,7 +188,9 @@ func (bridge *Bridge) NewUser(dbUser *database.User) *User {
user.RelayWhitelisted = user.bridge.Config.Bridge.Permissions.IsRelayWhitelisted(user.MXID)
user.Whitelisted = user.bridge.Config.Bridge.Permissions.IsWhitelisted(user.MXID)
user.Admin = user.bridge.Config.Bridge.Permissions.IsAdmin(user.MXID)
if user.bridge.Config.Bridge.HistorySync.Backfill {
go user.handleHistorySyncsLoop()
}
return user
}
@ -692,7 +694,9 @@ func (user *User) HandleEvent(event interface{}) {
portal := user.GetPortalByMessageSource(v.Info.MessageSource)
portal.messages <- PortalMessage{undecryptable: v, source: user}
case *events.HistorySync:
if user.bridge.Config.Bridge.HistorySync.Backfill {
user.historySyncs <- v
}
case *events.Mute:
portal := user.GetPortalByJID(v.JID)
if portal != nil {