Преглед изворни кода

Add option to disable backfilling in big guilds

Tulir Asokan пре 2 година
родитељ
комит
533054b8a0
4 измењених фајлова са 10 додато и 1 уклоњено
  1. 1 0
      config/bridge.go
  2. 1 0
      config/upgrade.go
  3. 5 0
      example-config.yaml
  4. 3 1
      user.go

+ 1 - 0
config/bridge.go

@@ -71,6 +71,7 @@ type BridgeConfig struct {
 			Initial BackfillLimitPart `yaml:"initial"`
 			Initial BackfillLimitPart `yaml:"initial"`
 			Missed  BackfillLimitPart `yaml:"missed"`
 			Missed  BackfillLimitPart `yaml:"missed"`
 		} `yaml:"forward_limits"`
 		} `yaml:"forward_limits"`
+		MaxGuildMembers int `yaml:"max_guild_members"`
 	} `yaml:"backfill"`
 	} `yaml:"backfill"`
 
 
 	Encryption bridgeconfig.EncryptionConfig `yaml:"encryption"`
 	Encryption bridgeconfig.EncryptionConfig `yaml:"encryption"`

+ 1 - 0
config/upgrade.go

@@ -72,6 +72,7 @@ func DoUpgrade(helper *up.Helper) {
 	helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "initial", "channel")
 	helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "initial", "channel")
 	helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "missed", "dm")
 	helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "missed", "dm")
 	helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "missed", "channel")
 	helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "missed", "channel")
+	helper.Copy(up.Int, "bridge", "backfill", "max_guild_members")
 	helper.Copy(up.Bool, "bridge", "encryption", "allow")
 	helper.Copy(up.Bool, "bridge", "encryption", "allow")
 	helper.Copy(up.Bool, "bridge", "encryption", "default")
 	helper.Copy(up.Bool, "bridge", "encryption", "default")
 	helper.Copy(up.Bool, "bridge", "encryption", "require")
 	helper.Copy(up.Bool, "bridge", "encryption", "require")

+ 5 - 0
example-config.yaml

@@ -186,6 +186,7 @@ bridge:
         # Optional extra text sent when joining a management room.
         # Optional extra text sent when joining a management room.
         additional_help: ""
         additional_help: ""
 
 
+    # Settings for backfilling messages.
     backfill:
     backfill:
         # Limits for forward backfilling.
         # Limits for forward backfilling.
         forward_limits:
         forward_limits:
@@ -202,6 +203,10 @@ bridge:
             missed:
             missed:
                 dm: 0
                 dm: 0
                 channel: 0
                 channel: 0
+        # Maximum members in a guild to enable backfilling. Set to -1 to disable limit.
+        # This can be used as a rough heuristic to disable backfilling in channels that are too active.
+        # Currently only applies to missed message backfill.
+        max_guild_members: -1
 
 
     # End-to-bridge encryption support options.
     # End-to-bridge encryption support options.
     #
     #

+ 3 - 1
user.go

@@ -843,7 +843,9 @@ func (user *User) handleGuild(meta *discordgo.Guild, timestamp time.Time, isInSp
 				}
 				}
 			} else {
 			} else {
 				portal.UpdateInfo(user, ch)
 				portal.UpdateInfo(user, ch)
-				portal.ForwardBackfillMissed(user, ch)
+				if user.bridge.Config.Bridge.Backfill.MaxGuildMembers < 0 || meta.MemberCount < user.bridge.Config.Bridge.Backfill.MaxGuildMembers {
+					portal.ForwardBackfillMissed(user, ch)
+				}
 			}
 			}
 		}
 		}
 	}
 	}