Skip to content

Commit

Permalink
Removed the max/min family of functions (mattermost#28679)
Browse files Browse the repository at this point in the history
They are in-built in Go now
```release-note
NONE
```
  • Loading branch information
agnivade authored Oct 10, 2024
1 parent 4440ace commit 3db139f
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 40 deletions.
7 changes: 0 additions & 7 deletions server/channels/app/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions server/channels/app/platform/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions server/channels/app/platform/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 2 additions & 9 deletions server/channels/store/localcachelayer/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion server/channels/store/sqlstore/shared_channel_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down
7 changes: 0 additions & 7 deletions server/channels/store/sqlstore/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
7 changes: 0 additions & 7 deletions server/public/pluginapi/cluster/mock_plugin_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3db139f

Please sign in to comment.