Skip to content

Commit

Permalink
[MM-60253] Avoid unnecessary cache clearing during LDAP sync (matterm…
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei authored Oct 3, 2024
1 parent da6b406 commit f3eee28
Show file tree
Hide file tree
Showing 14 changed files with 360 additions and 141 deletions.
20 changes: 13 additions & 7 deletions server/channels/app/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ func (a *App) UpdateChannelMemberNotifyProps(c request.CTX, data map[string]stri
a.invalidateCacheForChannelMembersNotifyProps(member.ChannelId)

// Notify the clients that the member notify props changed
err = a.sendUpdateChannelMemberNotifyPropsEvent(member)
err = a.sendUpdateChannelMemberEvent(member)
if err != nil {
return nil, model.NewAppError("UpdateChannelMemberNotifyProps", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
Expand Down Expand Up @@ -1339,7 +1339,7 @@ func (a *App) PatchChannelMembersNotifyProps(c request.CTX, members []*model.Cha

// Notify clients that their notify props have changed
for _, member := range updated {
err := a.sendUpdateChannelMemberNotifyPropsEvent(member)
err := a.sendUpdateChannelMemberEvent(member)
if err != nil {
c.Logger().Warn("Failed to send WebSocket event for updated channel member notify props", mlog.Err(err))
}
Expand All @@ -1348,7 +1348,7 @@ func (a *App) PatchChannelMembersNotifyProps(c request.CTX, members []*model.Cha
return updated, nil
}

func (a *App) sendUpdateChannelMemberNotifyPropsEvent(member *model.ChannelMember) error {
func (a *App) sendUpdateChannelMemberEvent(member *model.ChannelMember) error {
evt := model.NewWebSocketEvent(model.WebsocketEventChannelMemberUpdated, "", "", member.UserId, nil, "")
memberJSON, jsonErr := json.Marshal(member)
if jsonErr != nil {
Expand Down Expand Up @@ -1962,9 +1962,11 @@ func (a *App) GetAllChannels(c request.CTX, page, perPage int, opts model.Channe
opts.ExcludeChannelNames = a.DefaultChannelNames(c)
}
storeOpts := store.ChannelSearchOpts{
ExcludeChannelNames: opts.ExcludeChannelNames,
NotAssociatedToGroup: opts.NotAssociatedToGroup,
IncludeDeleted: opts.IncludeDeleted,
ExcludeChannelNames: opts.ExcludeChannelNames,
GroupConstrained: opts.GroupConstrained,
ExcludeGroupConstrained: opts.ExcludeGroupConstrained,
ExcludePolicyConstrained: opts.ExcludePolicyConstrained,
IncludePolicyID: opts.IncludePolicyID,
}
Expand All @@ -1981,9 +1983,13 @@ func (a *App) GetAllChannelsCount(c request.CTX, opts model.ChannelSearchOpts) (
opts.ExcludeChannelNames = a.DefaultChannelNames(c)
}
storeOpts := store.ChannelSearchOpts{
ExcludeChannelNames: opts.ExcludeChannelNames,
NotAssociatedToGroup: opts.NotAssociatedToGroup,
IncludeDeleted: opts.IncludeDeleted,
NotAssociatedToGroup: opts.NotAssociatedToGroup,
IncludeDeleted: opts.IncludeDeleted,
ExcludeChannelNames: opts.ExcludeChannelNames,
GroupConstrained: opts.GroupConstrained,
ExcludeGroupConstrained: opts.ExcludeGroupConstrained,
ExcludePolicyConstrained: opts.ExcludePolicyConstrained,
IncludePolicyID: opts.IncludePolicyID,
}
count, err := a.Srv().Store().Channel().GetAllChannelsCount(storeOpts)
if err != nil {
Expand Down
45 changes: 30 additions & 15 deletions server/channels/app/syncables.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,26 +234,47 @@ func (a *App) SyncSyncableRoles(rctx request.CTX, syncableID string, syncableTyp

switch syncableType {
case model.GroupSyncableTypeTeam:
nErr := a.Srv().Store().Team().UpdateMembersRole(syncableID, permittedAdmins)
if nErr != nil {
return model.NewAppError("App.SyncSyncableRoles", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
var updatedMembers []*model.TeamMember
updatedMembers, err = a.Srv().Store().Team().UpdateMembersRole(syncableID, permittedAdmins)
if err != nil {
return model.NewAppError("App.SyncSyncableRoles", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(err)
}

for _, member := range updatedMembers {
a.ClearSessionCacheForUser(member.UserId)

if appErr := a.sendUpdatedTeamMemberEvent(member); appErr != nil {
rctx.Logger().Warn("Error sending channel member updated websocket event", mlog.Err(appErr))
}
}
return nil
case model.GroupSyncableTypeChannel:
nErr := a.Srv().Store().Channel().UpdateMembersRole(syncableID, permittedAdmins)
if nErr != nil {
return model.NewAppError("App.SyncSyncableRoles", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
var updatedMembers []*model.ChannelMember
updatedMembers, err = a.Srv().Store().Channel().UpdateMembersRole(syncableID, permittedAdmins)
if err != nil {
return model.NewAppError("App.SyncSyncableRoles", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(err)
}

for _, member := range updatedMembers {
a.ClearSessionCacheForUser(member.UserId)

if appErr := a.sendUpdateChannelMemberEvent(member); appErr != nil {
rctx.Logger().Warn("Error sending channel member updated websocket event", mlog.Err(appErr))
}
}
return nil
default:
return model.NewAppError("App.SyncSyncableRoles", "groups.unsupported_syncable_type", map[string]any{"Value": syncableType}, "", http.StatusInternalServerError)
}

return nil
}

// SyncRolesAndMembership updates the SchemeAdmin status and membership of all of the members of the given
// syncable.
func (a *App) SyncRolesAndMembership(rctx request.CTX, syncableID string, syncableType model.GroupSyncableType, includeRemovedMembers bool) {
a.SyncSyncableRoles(rctx, syncableID, syncableType)
appErr := a.SyncSyncableRoles(rctx, syncableID, syncableType)
if appErr != nil {
rctx.Logger().Warn("Error syncing syncable roles", mlog.Err(appErr))
}

lastJob, _ := a.Srv().Store().Job().GetNewestJobByStatusAndType(model.JobStatusSuccess, model.JobTypeLdapSync)
var since int64
Expand All @@ -272,9 +293,6 @@ func (a *App) SyncRolesAndMembership(rctx request.CTX, syncableID string, syncab
if err := a.deleteGroupConstrainedTeamMemberships(rctx, &syncableID); err != nil {
rctx.Logger().Warn("Error deleting group constrained team memberships", mlog.Err(err))
}
if err := a.ClearTeamMembersCache(syncableID); err != nil {
rctx.Logger().Warn("Error clearing team members cache", mlog.Err(err))
}
case model.GroupSyncableTypeChannel:
params.ScopedChannelID = &syncableID
if err := a.createDefaultChannelMemberships(rctx, params); err != nil {
Expand All @@ -283,8 +301,5 @@ func (a *App) SyncRolesAndMembership(rctx request.CTX, syncableID string, syncab
if err := a.deleteGroupConstrainedChannelMemberships(rctx, &syncableID); err != nil {
rctx.Logger().Warn("Error deleting group constrained team memberships", mlog.Err(err))
}
if err := a.ClearChannelMembersCache(rctx, syncableID); err != nil {
rctx.Logger().Warn("Error clearing channel members cache", mlog.Err(err))
}
}
}
8 changes: 4 additions & 4 deletions server/channels/app/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func (a *App) UpdateTeamMemberRoles(c request.CTX, teamID string, userID string,

a.ClearSessionCacheForUser(userID)

if appErr := a.sendUpdatedMemberRoleEvent(userID, member); appErr != nil {
if appErr := a.sendUpdatedTeamMemberEvent(member); appErr != nil {
return nil, appErr
}

Expand Down Expand Up @@ -512,15 +512,15 @@ func (a *App) UpdateTeamMemberSchemeRoles(c request.CTX, teamID string, userID s

a.ClearSessionCacheForUser(userID)

if appErr := a.sendUpdatedMemberRoleEvent(userID, member); appErr != nil {
if appErr := a.sendUpdatedTeamMemberEvent(member); appErr != nil {
return nil, appErr
}

return member, nil
}

func (a *App) sendUpdatedMemberRoleEvent(userID string, member *model.TeamMember) *model.AppError {
message := model.NewWebSocketEvent(model.WebsocketEventMemberroleUpdated, "", "", userID, nil, "")
func (a *App) sendUpdatedTeamMemberEvent(member *model.TeamMember) *model.AppError {
message := model.NewWebSocketEvent(model.WebsocketEventMemberroleUpdated, "", "", member.UserId, nil, "")
tmJSON, jsonErr := json.Marshal(member)
if jsonErr != nil {
return model.NewAppError("sendUpdatedMemberRoleEvent", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr)
Expand Down
4 changes: 2 additions & 2 deletions server/channels/app/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2443,7 +2443,7 @@ func (a *App) PromoteGuestToUser(c request.CTX, user *model.User, requestorId st
}

for _, member := range teamMembers {
a.sendUpdatedMemberRoleEvent(user.Id, member)
a.sendUpdatedTeamMemberEvent(member)

channelMembers, appErr := a.GetChannelMembersForUser(c, member.TeamId, user.Id)
if appErr != nil {
Expand Down Expand Up @@ -2487,7 +2487,7 @@ func (a *App) DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError
}

for _, member := range teamMembers {
a.sendUpdatedMemberRoleEvent(user.Id, member)
a.sendUpdatedTeamMemberEvent(member)

channelMembers, appErr := a.GetChannelMembersForUser(c, member.TeamId, user.Id)
if appErr != nil {
Expand Down
12 changes: 6 additions & 6 deletions server/channels/store/opentracinglayer/opentracinglayer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions server/channels/store/retrylayer/retrylayer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f3eee28

Please sign in to comment.