Make backfill limits configurable
This commit is contained in:
parent
8e814bd05b
commit
e0df07e384
4 changed files with 25 additions and 4 deletions
16
backfill.go
16
backfill.go
|
@ -40,10 +40,14 @@ func (portal *Portal) initialForwardBackfill(user *User, markRead bool) {
|
|||
Logger()
|
||||
ctx := log.WithContext(context.TODO())
|
||||
|
||||
portal.forwardBackfill(ctx, user, time.Time{}, 50, markRead)
|
||||
portal.forwardBackfill(ctx, user, time.Time{}, portal.bridge.Config.Bridge.Backfill.InitialLimit, markRead)
|
||||
}
|
||||
|
||||
func (portal *Portal) missedForwardBackfill(user *User, lastMessageTS time.Time, lastMessageID string, markRead bool) bool {
|
||||
if portal.bridge.Config.Bridge.Backfill.MissedLimit == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
portal.forwardBackfillLock.Lock()
|
||||
defer portal.forwardBackfillLock.Unlock()
|
||||
log := portal.zlog.With().
|
||||
|
@ -76,7 +80,7 @@ func (portal *Portal) missedForwardBackfill(user *User, lastMessageTS time.Time,
|
|||
Str("latest_message_id", lastMessageID).
|
||||
Time("last_bridged_ts", portal.lastMessageTS).
|
||||
Msg("Backfilling missed messages")
|
||||
return portal.forwardBackfill(ctx, user, portal.lastMessageTS, 100, markRead)
|
||||
return portal.forwardBackfill(ctx, user, portal.lastMessageTS, portal.bridge.Config.Bridge.Backfill.MissedLimit, markRead)
|
||||
}
|
||||
|
||||
func (portal *Portal) deterministicEventID(messageID string, part int) id.EventID {
|
||||
|
@ -85,9 +89,13 @@ func (portal *Portal) deterministicEventID(messageID string, part int) id.EventI
|
|||
return id.EventID(fmt.Sprintf("$%s:messages.google.com", base64.RawURLEncoding.EncodeToString(sum[:])))
|
||||
}
|
||||
|
||||
func (portal *Portal) forwardBackfill(ctx context.Context, user *User, after time.Time, limit int64, markRead bool) bool {
|
||||
func (portal *Portal) forwardBackfill(ctx context.Context, user *User, after time.Time, limit int, markRead bool) bool {
|
||||
if limit == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
log := zerolog.Ctx(ctx)
|
||||
resp, err := user.Client.FetchMessages(portal.ID, limit, nil)
|
||||
resp, err := user.Client.FetchMessages(portal.ID, int64(limit), nil)
|
||||
if err != nil {
|
||||
portal.zlog.Error().Err(err).Msg("Failed to fetch messages")
|
||||
return false
|
||||
|
|
|
@ -39,6 +39,11 @@ type BridgeConfig struct {
|
|||
SyncDirectChatList bool `yaml:"sync_direct_chat_list"`
|
||||
InitialChatSyncCount int `yaml:"initial_chat_sync_count"`
|
||||
|
||||
Backfill struct {
|
||||
InitialLimit int `yaml:"initial_limit"`
|
||||
MissedLimit int `yaml:"missed_limit"`
|
||||
} `yaml:"backfill"`
|
||||
|
||||
DoublePuppetServerMap map[string]string `yaml:"double_puppet_server_map"`
|
||||
DoublePuppetAllowDiscovery bool `yaml:"double_puppet_allow_discovery"`
|
||||
LoginSharedSecretMap map[string]string `yaml:"login_shared_secret_map"`
|
||||
|
|
|
@ -44,6 +44,8 @@ func DoUpgrade(helper *up.Helper) {
|
|||
helper.Copy(up.Int, "bridge", "portal_message_buffer")
|
||||
helper.Copy(up.Bool, "bridge", "sync_direct_chat_list")
|
||||
helper.Copy(up.Int, "bridge", "initial_chat_sync_count")
|
||||
helper.Copy(up.Int, "bridge", "backfill", "initial_limit")
|
||||
helper.Copy(up.Int, "bridge", "backfill", "missed_limit")
|
||||
helper.Copy(up.Map, "bridge", "double_puppet_server_map")
|
||||
helper.Copy(up.Bool, "bridge", "double_puppet_allow_discovery")
|
||||
helper.Copy(up.Map, "bridge", "login_shared_secret_map")
|
||||
|
|
|
@ -126,6 +126,12 @@ bridge:
|
|||
sync_direct_chat_list: false
|
||||
# Number of chats to sync when connecting to Google Messages.
|
||||
initial_chat_sync_count: 25
|
||||
# Backfill settings
|
||||
backfill:
|
||||
# Number of messages to backfill in new chats.
|
||||
initial_limit: 50
|
||||
# Number of messages to backfill on startup if the last message ID in the chat sync doesn't match the last bridged message.
|
||||
missed_limit: 100
|
||||
|
||||
# Servers to always allow double puppeting from
|
||||
double_puppet_server_map:
|
||||
|
|
Loading…
Reference in a new issue