Revert "MM-55295: Improve DB performance of some APIs (#25318)" (#25852)

This reverts commit ec88ab4ee9.
Этот коммит содержится в:
Claudio Costa
2024-01-05 10:05:37 -06:00
коммит произвёл GitHub
родитель 4b88bfd5fb
Коммит 077221a940
12 изменённых файлов: 53 добавлений и 189 удалений

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

@@ -1126,16 +1126,26 @@ func (s SqlChannelStore) GetChannelsByUser(userId string, includeDeleted bool, l
return channels, nil
}
func (s SqlChannelStore) GetAllChannelMemberIdsByChannelId(channelID string) ([]string, error) {
userIDs := []string{}
err := s.GetReplicaX().Select(&userIDs, `SELECT UserId
FROM ChannelMembers
WHERE ChannelId=?`, channelID)
func (s SqlChannelStore) GetAllChannelMembersById(channelID string) ([]string, error) {
sql, args, err := s.channelMembersForTeamWithSchemeSelectQuery.Where(sq.Eq{
"ChannelId": channelID,
}).ToSql()
if err != nil {
return nil, errors.Wrap(err, "GetAllChannelMembersById_ToSql")
}
dbMembers := channelMemberWithSchemeRolesList{}
err = s.GetReplicaX().Select(&dbMembers, sql, args...)
if err != nil {
return nil, errors.Wrapf(err, "failed to get ChannelMembers with channelID=%s", channelID)
}
return userIDs, nil
res := make([]string, len(dbMembers))
for i, member := range dbMembers.ToModel() {
res[i] = member.UserId
}
return res, nil
}
func (s SqlChannelStore) GetAllChannels(offset, limit int, opts store.ChannelSearchOpts) (model.ChannelListWithTeamData, error) {
@@ -2060,33 +2070,6 @@ func (s SqlChannelStore) GetMember(ctx context.Context, channelID string, userID
return dbMember.ToModel(), nil
}
func (s SqlChannelStore) GetMemberOnly(ctx context.Context, channelID string, userID string) (*model.ChannelMember, error) {
var dbMember model.ChannelMember
if err := s.DBXFromContext(ctx).Get(&dbMember, `SELECT ChannelId,
UserId,
Roles,
LastViewedAt,
MsgCount,
MentionCount,
MentionCountRoot,
COALESCE(UrgentMentionCount, 0) AS UrgentMentionCount,
MsgCountRoot,
NotifyProps,
LastUpdateAt,
SchemeUser,
SchemeAdmin,
SchemeGuest
FROM ChannelMembers
WHERE ChannelId=? AND UserId=?`, channelID, userID); err != nil {
if err == sql.ErrNoRows {
return nil, store.NewErrNotFound("ChannelMember", fmt.Sprintf("channelId=%s, userId=%s", channelID, userID))
}
return nil, errors.Wrapf(err, "failed to get ChannelMember with channelId=%s and userId=%s", channelID, userID)
}
return &dbMember, nil
}
func (s SqlChannelStore) InvalidateAllChannelMembersForUser(userId string) {
allChannelMembersForUserCache.Remove(userId)
allChannelMembersForUserCache.Remove(userId + "_deleted")