Reduce number of calls to IsCRTEnabled (#23963)

In a single createPost flow, there were
3 separate calls to App.IsCRTEnabled. This
showed up very slightly in the CPU profiles.

Not a big deal, but good to get it out of
the way.

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2023-07-10 10:18:55 +05:30
коммит произвёл GitHub
родитель b5a3eee739
Коммит 49e1d039f5
6 изменённых файлов: 15 добавлений и 14 удалений

Просмотреть файл

@@ -2953,7 +2953,7 @@ func (a *App) SearchChannelsUserNotIn(c request.CTX, teamID string, userID strin
return channelList, nil
}
func (a *App) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported bool) (map[string]int64, *model.AppError) {
func (a *App) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported, isCRTEnabled bool) (map[string]int64, *model.AppError) {
// I start looking for channels with notifications before I mark it as read, to clear the push notifications if needed
channelsToClearPushNotifications := []string{}
if a.canSendPushNotifications() {
@@ -2996,7 +2996,7 @@ func (a *App) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID st
}
var err error
updateThreads := *a.Config().ServiceSettings.ThreadAutoFollow && (!collapsedThreadsSupported || !a.IsCRTEnabledForUser(c, userID))
updateThreads := *a.Config().ServiceSettings.ThreadAutoFollow && (!collapsedThreadsSupported || !isCRTEnabled)
if updateThreads {
err = a.Srv().Store().Thread().MarkAllAsReadByChannels(userID, channelIDs)
if err != nil {
@@ -3026,7 +3026,7 @@ func (a *App) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID st
a.clearPushNotification(currentSessionId, userID, channelID, "")
}
if updateThreads && a.IsCRTEnabledForUser(c, userID) {
if updateThreads && isCRTEnabled {
timestamp := model.GetMillis()
for _, channelID := range channelIDs {
message := model.NewWebSocketEvent(model.WebsocketEventThreadReadChanged, "", channelID, userID, nil, "")
@@ -3057,7 +3057,7 @@ func (a *App) ViewChannel(c request.CTX, view *model.ChannelView, userID string,
return map[string]int64{}, nil
}
return a.MarkChannelsAsViewed(c, channelIDs, userID, currentSessionId, collapsedThreadsSupported)
return a.MarkChannelsAsViewed(c, channelIDs, userID, currentSessionId, collapsedThreadsSupported, a.IsCRTEnabledForUser(c, userID))
}
func (a *App) PermanentDeleteChannel(c request.CTX, channel *model.Channel) *model.AppError {