From 3db139f7462124f78625f801fcee393b4affed50 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Thu, 10 Oct 2024 22:14:21 +0530 Subject: [PATCH] Removed the max/min family of functions (#28679) They are in-built in Go now ```release-note NONE ``` --- server/channels/app/notification.go | 7 ------- server/channels/app/platform/service.go | 4 ++-- server/channels/app/platform/utils.go | 7 ------- server/channels/store/localcachelayer/layer.go | 11 ++--------- .../channels/store/sqlstore/shared_channel_store.go | 2 +- server/channels/store/sqlstore/utils.go | 7 ------- .../public/pluginapi/cluster/mock_plugin_api_test.go | 7 ------- 7 files changed, 5 insertions(+), 40 deletions(-) diff --git a/server/channels/app/notification.go b/server/channels/app/notification.go index 3d45b1d74fb1a..854abf8237a83 100644 --- a/server/channels/app/notification.go +++ b/server/channels/app/notification.go @@ -1138,13 +1138,6 @@ func (a *App) getExplicitMentionsAndKeywords(c request.CTX, post *model.Post, ch return mentions, keywords } -func max(a, b int64) int64 { - if a < b { - return b - } - return a -} - func (a *App) userAllowsEmail(c request.CTX, user *model.User, channelMemberNotificationProps model.StringMap, post *model.Post) bool { // if user is a bot account or remote, then we do not send email if user.IsBot || user.IsRemote() { diff --git a/server/channels/app/platform/service.go b/server/channels/app/platform/service.go index ac32eb71ab2bb..4ca223189c55a 100644 --- a/server/channels/app/platform/service.go +++ b/server/channels/app/platform/service.go @@ -303,7 +303,7 @@ func New(sc ServiceConfig, options ...Option) (*PlatformService, error) { Name: "Status", Size: model.StatusCacheSize, Striped: true, - StripedBuckets: maxInt(runtime.NumCPU()-1, 1), + StripedBuckets: max(runtime.NumCPU()-1, 1), DefaultExpiry: 30 * time.Minute, }) if err != nil { @@ -314,7 +314,7 @@ func New(sc ServiceConfig, options ...Option) (*PlatformService, error) { Name: "Session", Size: model.SessionCacheSize, Striped: true, - StripedBuckets: maxInt(runtime.NumCPU()-1, 1), + StripedBuckets: max(runtime.NumCPU()-1, 1), }) if err != nil { return nil, fmt.Errorf("could not create session cache: %w", err) diff --git a/server/channels/app/platform/utils.go b/server/channels/app/platform/utils.go index c8f48c0495cd2..2e7af04bee214 100644 --- a/server/channels/app/platform/utils.go +++ b/server/channels/app/platform/utils.go @@ -14,13 +14,6 @@ func getKeyHash(key string) string { return base64.StdEncoding.EncodeToString(hash.Sum(nil)) } -func maxInt(a, b int) int { - if a > b { - return a - } - return b -} - // allocateCacheTargets is used to fill target value types // for getting items from cache. func allocateCacheTargets[T any](l int) []any { diff --git a/server/channels/store/localcachelayer/layer.go b/server/channels/store/localcachelayer/layer.go index 20e55c0fdd129..1003a01d6103d 100644 --- a/server/channels/store/localcachelayer/layer.go +++ b/server/channels/store/localcachelayer/layer.go @@ -152,7 +152,7 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf DefaultExpiry: RoleCacheSec * time.Second, InvalidateClusterEvent: model.ClusterEventInvalidateCacheForRoles, Striped: true, - StripedBuckets: maxInt(runtime.NumCPU()-1, 1), + StripedBuckets: max(runtime.NumCPU()-1, 1), }); err != nil { return } @@ -336,7 +336,7 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf DefaultExpiry: UserProfileByIDSec * time.Second, InvalidateClusterEvent: model.ClusterEventInvalidateCacheForProfileByIds, Striped: true, - StripedBuckets: maxInt(runtime.NumCPU()-1, 1), + StripedBuckets: max(runtime.NumCPU()-1, 1), }); err != nil { return } @@ -394,13 +394,6 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf return } -func maxInt(a, b int) int { - if a > b { - return a - } - return b -} - func (s LocalCacheStore) Reaction() store.ReactionStore { return s.reaction } diff --git a/server/channels/store/sqlstore/shared_channel_store.go b/server/channels/store/sqlstore/shared_channel_store.go index 73d8d2c92da7f..e47b03d4e197e 100644 --- a/server/channels/store/sqlstore/shared_channel_store.go +++ b/server/channels/store/sqlstore/shared_channel_store.go @@ -818,7 +818,7 @@ func (s SqlSharedChannelStore) UpdateUserLastSyncAt(userID string, channelID str return err } - updateAt := maxInt64(user.UpdateAt, user.LastPictureUpdate) + updateAt := max(user.UpdateAt, user.LastPictureUpdate) query := s.getQueryBuilder(). Update("SharedChannelUsers AS scu"). diff --git a/server/channels/store/sqlstore/utils.go b/server/channels/store/sqlstore/utils.go index 0aa87cb7afd9f..6ce0dda45b370 100644 --- a/server/channels/store/sqlstore/utils.go +++ b/server/channels/store/sqlstore/utils.go @@ -192,13 +192,6 @@ func trimInput(input string) string { return input } -func maxInt64(a, b int64) int64 { - if a > b { - return a - } - return b -} - // Adds backtiks to the column name for MySQL, this is required if // the column name is a reserved keyword. // diff --git a/server/public/pluginapi/cluster/mock_plugin_api_test.go b/server/public/pluginapi/cluster/mock_plugin_api_test.go index 5a5487a4ae497..d1f53c95f2f81 100644 --- a/server/public/pluginapi/cluster/mock_plugin_api_test.go +++ b/server/public/pluginapi/cluster/mock_plugin_api_test.go @@ -102,13 +102,6 @@ func (pluginAPI *mockPluginAPI) KVList(page, count int) ([]string, *model.AppErr return keys[start:end], nil } -func min(a, b int) int { - if a < b { - return a - } - return b -} - func (pluginAPI *mockPluginAPI) KVSetWithOptions(key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError) { pluginAPI.lock.Lock() defer pluginAPI.lock.Unlock()