mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
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 ```
This commit is contained in:
parent
b5a3eee739
commit
49e1d039f5
@ -921,7 +921,7 @@ type AppIface interface {
|
||||
Log() *mlog.Logger
|
||||
LoginByOAuth(c *request.Context, service string, userData io.Reader, teamID string, tokenUser *model.User) (*model.User, *model.AppError)
|
||||
MakePermissionError(s *model.Session, permissions []*model.Permission) *model.AppError
|
||||
MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported bool) (map[string]int64, *model.AppError)
|
||||
MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported, isCRTEnabled bool) (map[string]int64, *model.AppError)
|
||||
MaxPostSize() int
|
||||
MessageExport() einterfaces.MessageExportInterface
|
||||
Metrics() einterfaces.MetricsInterface
|
||||
|
@ -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 {
|
||||
|
@ -1422,9 +1422,9 @@ func TestMarkChannelAsUnreadFromPost(t *testing.T) {
|
||||
unread, err = th.App.GetChannelUnread(th.Context, c1.Id, u2.Id)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, int64(4), unread.MsgCount)
|
||||
_, err = th.App.MarkChannelsAsViewed(th.Context, []string{c1.Id, pc1.Id}, u1.Id, "", false)
|
||||
_, err = th.App.MarkChannelsAsViewed(th.Context, []string{c1.Id, pc1.Id}, u1.Id, "", false, false)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.MarkChannelsAsViewed(th.Context, []string{c1.Id, pc1.Id}, u2.Id, "", false)
|
||||
_, err = th.App.MarkChannelsAsViewed(th.Context, []string{c1.Id, pc1.Id}, u2.Id, "", false, false)
|
||||
require.Nil(t, err)
|
||||
unread, err = th.App.GetChannelUnread(th.Context, c1.Id, u2.Id)
|
||||
require.Nil(t, err)
|
||||
@ -2146,7 +2146,7 @@ func TestMarkChannelsAsViewedPanic(t *testing.T) {
|
||||
mockThreadStore.On("MarkAllAsReadByChannels", "userID", []string{"channelID"}).Return(nil)
|
||||
mockStore.On("Thread").Return(&mockThreadStore)
|
||||
|
||||
_, appErr := th.App.MarkChannelsAsViewed(th.Context, []string{"channelID"}, "userID", th.Context.Session().Id, false)
|
||||
_, appErr := th.App.MarkChannelsAsViewed(th.Context, []string{"channelID"}, "userID", th.Context.Session().Id, false, false)
|
||||
require.Nil(t, appErr)
|
||||
}
|
||||
|
||||
@ -2256,7 +2256,7 @@ func TestViewChannelCollapsedThreadsTurnedOff(t *testing.T) {
|
||||
require.Truef(t, found, "did not find created thread in user's threads")
|
||||
|
||||
// Mark channel as read from a client that supports CRT
|
||||
_, appErr = th.App.MarkChannelsAsViewed(th.Context, []string{c1.Id}, u1.Id, th.Context.Session().Id, true)
|
||||
_, appErr = th.App.MarkChannelsAsViewed(th.Context, []string{c1.Id}, u1.Id, th.Context.Session().Id, true, th.App.IsCRTEnabledForUser(th.Context, u1.Id))
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Thread should be marked as read because CRT has been turned off by user
|
||||
|
@ -93,7 +93,7 @@ func TestExportUserChannels(t *testing.T) {
|
||||
Value: "true",
|
||||
}
|
||||
|
||||
_, appErr := th.App.MarkChannelsAsViewed(th.Context, []string{th.BasicPost.ChannelId}, user.Id, "", true)
|
||||
_, appErr := th.App.MarkChannelsAsViewed(th.Context, []string{th.BasicPost.ChannelId}, user.Id, "", true, th.App.IsCRTEnabledForUser(th.Context, user.Id))
|
||||
require.Nil(t, appErr)
|
||||
|
||||
var preferences model.Preferences
|
||||
|
@ -12594,7 +12594,7 @@ func (a *OpenTracingAppLayer) MarkChannelAsUnreadFromPost(c request.CTX, postID
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported bool) (map[string]int64, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported bool, isCRTEnabled bool) (map[string]int64, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.MarkChannelsAsViewed")
|
||||
|
||||
@ -12606,7 +12606,7 @@ func (a *OpenTracingAppLayer) MarkChannelsAsViewed(c request.CTX, channelIDs []s
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.MarkChannelsAsViewed(c, channelIDs, userID, currentSessionId, collapsedThreadsSupported)
|
||||
resultVar0, resultVar1 := a.app.MarkChannelsAsViewed(c, channelIDs, userID, currentSessionId, collapsedThreadsSupported, isCRTEnabled)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
|
@ -100,9 +100,10 @@ func (a *App) CreatePostAsUser(c request.CTX, post *model.Post, currentSessionId
|
||||
// the post is NOT a reply post with CRT enabled
|
||||
_, fromWebhook := post.GetProps()["from_webhook"]
|
||||
_, fromBot := post.GetProps()["from_bot"]
|
||||
isCRTReply := post.RootId != "" && a.IsCRTEnabledForUser(c, post.UserId)
|
||||
isCRTEnabled := a.IsCRTEnabledForUser(c, post.UserId)
|
||||
isCRTReply := post.RootId != "" && isCRTEnabled
|
||||
if !fromWebhook && !fromBot && !isCRTReply {
|
||||
if _, err := a.MarkChannelsAsViewed(c, []string{post.ChannelId}, post.UserId, currentSessionId, true); err != nil {
|
||||
if _, err := a.MarkChannelsAsViewed(c, []string{post.ChannelId}, post.UserId, currentSessionId, true, isCRTEnabled); err != nil {
|
||||
c.Logger().Warn(
|
||||
"Encountered error updating last viewed",
|
||||
mlog.String("channel_id", post.ChannelId),
|
||||
|
Loading…
Reference in New Issue
Block a user