From d1ae710d457b3ce20565e5491dc4dde09a7eb268 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Thu, 12 Sep 2024 20:40:44 +0200 Subject: [PATCH] Adds a ConnectedWorkspaces.MaxPostsPerSync configuration property (#28154) * Adds a ConnectedWorkspaces.MaxPostsPerSync configuration property * Fix linter --- server/platform/services/sharedchannel/service.go | 1 - .../platform/services/sharedchannel/sync_send_remote.go | 9 +++++---- server/platform/services/telemetry/telemetry.go | 1 + server/public/model/config.go | 7 +++++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/server/platform/services/sharedchannel/service.go b/server/platform/services/sharedchannel/service.go index e1848709b3e..192d8a8a2b1 100644 --- a/server/platform/services/sharedchannel/service.go +++ b/server/platform/services/sharedchannel/service.go @@ -24,7 +24,6 @@ const ( TopicChannelInvite = "sharedchannel_invite" TopicUploadCreate = "sharedchannel_upload" MaxRetries = 3 - MaxPostsPerSync = 50 // a bit more than 4 typical screenfulls of posts MaxUsersPerSync = 25 NotifyRemoteOfflineThreshold = time.Second * 10 NotifyMinimumDelay = time.Second * 2 diff --git a/server/platform/services/sharedchannel/sync_send_remote.go b/server/platform/services/sharedchannel/sync_send_remote.go index 5521e9c75d0..b1b2067c90f 100644 --- a/server/platform/services/sharedchannel/sync_send_remote.go +++ b/server/platform/services/sharedchannel/sync_send_remote.go @@ -280,12 +280,13 @@ func (scs *Service) fetchPostsForSync(sd *syncData) error { LastPostCreateAt: sd.scr.LastPostCreateAt, LastPostCreateID: sd.scr.LastPostCreateID, } + maxPostsPerSync := *scs.server.Config().ConnectedWorkspacesSettings.MaxPostsPerSync // Fetch all newly created posts first. This is to ensure that post order is preserved for sync targets // that cannot set the CreateAt timestamp for incoming posts (e.g. MS Teams). If we simply used UpdateAt // then posts could get out of order. For example: p1 created, p2 created, p1 updated... sync'ing on UpdateAt // would order the posts p2, p1. - posts, nextCursor, err := scs.server.GetStore().Post().GetPostsSinceForSync(options, cursor, MaxPostsPerSync) + posts, nextCursor, err := scs.server.GetStore().Post().GetPostsSinceForSync(options, cursor, maxPostsPerSync) if err != nil { return fmt.Errorf("could not fetch new posts for sync: %w", err) } @@ -295,10 +296,10 @@ func (scs *Service) fetchPostsForSync(sd *syncData) error { cache := postsSliceToMap(posts) // Fill remaining batch capacity with updated posts. - if len(posts) < MaxPostsPerSync { + if len(posts) < maxPostsPerSync { options.SinceCreateAt = false // use 'nextcursor' as it has the correct xxxUpdateAt values, and the updsted xxxCreateAt values. - posts, nextCursor, err = scs.server.GetStore().Post().GetPostsSinceForSync(options, nextCursor, MaxPostsPerSync-len(posts)) + posts, nextCursor, err = scs.server.GetStore().Post().GetPostsSinceForSync(options, nextCursor, maxPostsPerSync-len(posts)) if err != nil { return fmt.Errorf("could not fetch modified posts for sync: %w", err) } @@ -308,7 +309,7 @@ func (scs *Service) fetchPostsForSync(sd *syncData) error { } sd.resultNextCursor = nextCursor - sd.resultRepeat = count >= MaxPostsPerSync + sd.resultRepeat = count >= maxPostsPerSync return nil } diff --git a/server/platform/services/telemetry/telemetry.go b/server/platform/services/telemetry/telemetry.go index ed94ac45807..b07a3dffcd3 100644 --- a/server/platform/services/telemetry/telemetry.go +++ b/server/platform/services/telemetry/telemetry.go @@ -894,6 +894,7 @@ func (ts *TelemetryService) trackConfig() { "enable_shared_channels": *cfg.ConnectedWorkspacesSettings.EnableSharedChannels, "enable_remote_cluster_service": *cfg.ConnectedWorkspacesSettings.EnableRemoteClusterService && cfg.FeatureFlags.EnableRemoteClusterService, "disable_shared_channels_status_sync": *cfg.ConnectedWorkspacesSettings.DisableSharedChannelsStatusSync, + "max_posts_per_sync": *cfg.ConnectedWorkspacesSettings.MaxPostsPerSync, }) // Convert feature flags to map[string]any for sending diff --git a/server/public/model/config.go b/server/public/model/config.go index e6791798262..3e571efd14a 100644 --- a/server/public/model/config.go +++ b/server/public/model/config.go @@ -265,6 +265,8 @@ const ( OpenidSettingsDefaultScope = "profile openid email" LocalModeSocketPath = "/var/tmp/mattermost_local.socket" + + ConnectedWorkspacesSettingsDefaultMaxPostsPerSync = 50 // a bit more than 4 typical screenfulls of posts ) func GetDefaultAppCustomURLSchemes() []string { @@ -3278,6 +3280,7 @@ type ConnectedWorkspacesSettings struct { EnableSharedChannels *bool EnableRemoteClusterService *bool DisableSharedChannelsStatusSync *bool + MaxPostsPerSync *int } func (c *ConnectedWorkspacesSettings) SetDefaults(isUpdate bool, e ExperimentalSettings) { @@ -3300,6 +3303,10 @@ func (c *ConnectedWorkspacesSettings) SetDefaults(isUpdate bool, e ExperimentalS if c.DisableSharedChannelsStatusSync == nil { c.DisableSharedChannelsStatusSync = NewPointer(false) } + + if c.MaxPostsPerSync == nil { + c.MaxPostsPerSync = NewPointer(ConnectedWorkspacesSettingsDefaultMaxPostsPerSync) + } } type GlobalRelayMessageExportSettings struct {