[GH-19150] Remove strings in all channel types for constants (#19535)

Automatic Merge
Этот коммит содержится в:
Kitae Kim
2022-02-11 19:04:18 +09:00
коммит произвёл GitHub
родитель 0a17a9a6d8
Коммит ff288b488c
15 изменённых файлов: 74 добавлений и 70 удалений

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

@@ -693,7 +693,7 @@ func (s SqlChannelStore) saveChannelT(transaction *sqlxTxWrapper, channel *model
if channel.Type != model.ChannelTypeDirect && channel.Type != model.ChannelTypeGroup && maxChannelsPerTeam >= 0 {
var count int64
if err := transaction.Get(&count, "SELECT COUNT(0) FROM Channels WHERE TeamId = ? AND DeleteAt = 0 AND (Type = 'O' OR Type = 'P')", channel.TeamId); err != nil {
if err := transaction.Get(&count, "SELECT COUNT(0) FROM Channels WHERE TeamId = ? AND DeleteAt = 0 AND (Type = ? OR Type = ?)", channel.TeamId, model.ChannelTypeOpen, model.ChannelTypePrivate); err != nil {
return nil, errors.Wrapf(err, "save_channel_count: teamId=%s", channel.TeamId)
} else if count >= maxChannelsPerTeam {
return nil, store.NewErrLimitExceeded("channels_per_team", int(count), "teamId="+channel.TeamId)
@@ -1439,7 +1439,7 @@ func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) (*model.
func (s SqlChannelStore) GetTeamChannels(teamId string) (model.ChannelList, error) {
data := model.ChannelList{}
err := s.GetReplicaX().Select(&data, "SELECT * FROM Channels WHERE TeamId = ? And Type != 'D' ORDER BY DisplayName", teamId)
err := s.GetReplicaX().Select(&data, "SELECT * FROM Channels WHERE TeamId = ? And Type != ? ORDER BY DisplayName", teamId, model.ChannelTypeDirect)
if err != nil {
return nil, errors.Wrapf(err, "failed to find Channels with teamId=%s", teamId)
}
@@ -1583,17 +1583,17 @@ func (s SqlChannelStore) GetDeleted(teamId string, offset int, limit int, userId
SELECT * FROM Channels
WHERE (TeamId = ? OR TeamId = '')
AND DeleteAt != 0
AND Type != 'P'
AND Type != ?
UNION
SELECT * FROM Channels
WHERE (TeamId = ? OR TeamId = '')
AND DeleteAt != 0
AND Type = 'P'
AND Type = ?
AND Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = ?)
ORDER BY DisplayName LIMIT ? OFFSET ?
`
if err := s.GetReplicaX().Select(&channels, query, teamId, teamId, userId, limit, offset); err != nil {
if err := s.GetReplicaX().Select(&channels, query, teamId, model.ChannelTypePrivate, teamId, model.ChannelTypePrivate, userId, limit, offset); err != nil {
if err == sql.ErrNoRows {
return nil, store.NewErrNotFound("Channel", fmt.Sprintf("TeamId=%s,UserId=%s", teamId, userId))
}
@@ -2640,7 +2640,7 @@ func (s SqlChannelStore) IncrementMentionCount(channelId string, userId string,
func (s SqlChannelStore) GetAll(teamId string) ([]*model.Channel, error) {
data := []*model.Channel{}
err := s.GetReplicaX().Select(&data, "SELECT * FROM Channels WHERE TeamId = ? AND Type != 'D' ORDER BY Name", teamId)
err := s.GetReplicaX().Select(&data, "SELECT * FROM Channels WHERE TeamId = ? AND Type != ? ORDER BY Name", teamId, model.ChannelTypeDirect)
if err != nil {
return nil, errors.Wrapf(err, "failed to find Channels with teamId=%s", teamId)
@@ -2743,7 +2743,7 @@ func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType model.Cha
return value, nil
}
func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType string) (int64, error) {
func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType model.ChannelType) (int64, error) {
query := s.getQueryBuilder().
Select("COUNT(Id) AS Value").
From("Channels").
@@ -2879,15 +2879,16 @@ func (s SqlChannelStore) Autocomplete(userID, term string, includeDeleted bool)
`+deleteFilter+`
SEARCH_CLAUSE
AND (
c.Type != 'P'
c.Type != :ChannelType
OR (
c.Type = 'P'
c.Type = :ChannelType
AND c.Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId)
)
)
ORDER BY c.DisplayName
`, term, map[string]interface{}{
"UserId": userID,
"UserId": userID,
"ChannelType": model.ChannelTypePrivate,
})
}
@@ -2908,18 +2909,19 @@ func (s SqlChannelStore) AutocompleteInTeam(teamID, userID, term string, include
`+deleteFilter+`
SEARCH_CLAUSE
AND (
c.Type != 'P'
c.Type != :ChannelType
OR (
c.Type = 'P'
c.Type = :ChannelType
AND c.Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId)
)
)
ORDER BY c.DisplayName
LIMIT :Limit
`, term, map[string]interface{}{
"TeamId": teamID,
"UserId": userID,
"Limit": model.ChannelSearchDefaultLimit,
"TeamId": teamID,
"UserId": userID,
"Limit": model.ChannelSearchDefaultLimit,
"ChannelType": model.ChannelTypePrivate,
})
}
@@ -2938,7 +2940,7 @@ func (s SqlChannelStore) AutocompleteInTeamForSearch(teamId string, userId strin
JOIN
ChannelMembers AS CM ON CM.ChannelId = C.Id
WHERE
(C.TeamId = :TeamId OR (C.TeamId = '' AND C.Type = 'G'))
(C.TeamId = :TeamId OR (C.TeamId = '' AND C.Type = :ChannelType))
AND CM.UserId = :UserId
` + deleteFilter + `
%v
@@ -2947,7 +2949,7 @@ func (s SqlChannelStore) AutocompleteInTeamForSearch(teamId string, userId strin
var channels model.ChannelList
if likeClause, likeTerm := s.buildLIKEClause(term, "Name, DisplayName, Purpose"); likeClause == "" {
if _, err := s.GetReplica().Select(&channels, fmt.Sprintf(queryFormat, ""), map[string]interface{}{"TeamId": teamId, "UserId": userId}); err != nil {
if _, err := s.GetReplica().Select(&channels, fmt.Sprintf(queryFormat, ""), map[string]interface{}{"TeamId": teamId, "UserId": userId, "ChannelType": model.ChannelTypeGroup}); err != nil {
return nil, errors.Wrapf(err, "failed to find Channels with term='%s'", term)
}
} else {
@@ -2958,7 +2960,7 @@ func (s SqlChannelStore) AutocompleteInTeamForSearch(teamId string, userId strin
fulltextQuery := fmt.Sprintf(queryFormat, "AND "+fulltextClause)
query := fmt.Sprintf("(%v) UNION (%v) LIMIT 50", likeQuery, fulltextQuery)
if _, err := s.GetReplica().Select(&channels, query, map[string]interface{}{"TeamId": teamId, "UserId": userId, "LikeTerm": likeTerm, "FulltextTerm": fulltextTerm}); err != nil {
if _, err := s.GetReplica().Select(&channels, query, map[string]interface{}{"TeamId": teamId, "UserId": userId, "LikeTerm": likeTerm, "FulltextTerm": fulltextTerm, "ChannelType": model.ChannelTypeGroup}); err != nil {
return nil, errors.Wrapf(err, "failed to find Channels with term='%s'", term)
}
}
@@ -2998,20 +3000,20 @@ func (s SqlChannelStore) autocompleteInTeamForSearchDirectMessages(userId string
%v
) AS OtherUsers ON OtherUsers.ChannelId = C.Id
WHERE
C.Type = 'D'
C.Type = :ChannelType
AND CM.UserId = :UserId
LIMIT 50`
var channels model.ChannelList
if likeClause, likeTerm := s.buildLIKEClause(term, "IU.Username, IU.Nickname"); likeClause == "" {
if _, err := s.GetReplica().Select(&channels, fmt.Sprintf(queryFormat, ""), map[string]interface{}{"UserId": userId}); err != nil {
if _, err := s.GetReplica().Select(&channels, fmt.Sprintf(queryFormat, ""), map[string]interface{}{"UserId": userId, "ChannelType": model.ChannelTypeDirect}); err != nil {
return nil, errors.Wrapf(err, "failed to find Channels with term='%s'", term)
}
} else {
query := fmt.Sprintf(queryFormat, "AND "+likeClause)
if _, err := s.GetReplica().Select(&channels, query, map[string]interface{}{"UserId": userId, "LikeTerm": likeTerm}); err != nil {
if _, err := s.GetReplica().Select(&channels, query, map[string]interface{}{"UserId": userId, "LikeTerm": likeTerm, "ChannelType": model.ChannelTypeDirect}); err != nil {
return nil, errors.Wrapf(err, "failed to find Channels with term='%s'", term)
}
}
@@ -3057,12 +3059,13 @@ func (s SqlChannelStore) SearchArchivedInTeam(teamId string, term string, userId
c.TeamId = :TeamId
SEARCH_CLAUSE
AND c.DeleteAt != 0
AND c.Type != 'P'
AND c.Type != :ChannelType
ORDER BY c.DisplayName
LIMIT 100
`, term, map[string]interface{}{
"TeamId": teamId,
"UserId": userId,
"TeamId": teamId,
"UserId": userId,
"ChannelType": model.ChannelTypePrivate,
})
privateChannels, privateErr := s.performSearch(`
@@ -3076,13 +3079,14 @@ func (s SqlChannelStore) SearchArchivedInTeam(teamId string, term string, userId
c.TeamId = :TeamId
SEARCH_CLAUSE
AND c.DeleteAt != 0
AND c.Type = 'P'
AND c.Type = :ChannelType
AND c.Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId)
ORDER BY c.DisplayName
LIMIT 100
`, term, map[string]interface{}{
"TeamId": teamId,
"UserId": userId,
"TeamId": teamId,
"UserId": userId,
"ChannelType": model.ChannelTypePrivate,
})
outputErr := publicErr
@@ -3422,7 +3426,7 @@ func (s SqlChannelStore) getSearchGroupChannelsQuery(userId, term string, isPost
JOIN
Users u on u.Id = cm.UserId
WHERE
c.Type = 'G'
c.Type = :ChannelType
AND
u.Id = :UserId
GROUP BY
@@ -3454,7 +3458,7 @@ func (s SqlChannelStore) getSearchGroupChannelsQuery(userId, term string, isPost
JOIN
Users u on u.Id = cm.UserId
WHERE
c.Type = 'G'
c.Type = :ChannelType
AND
u.Id = :UserId
GROUP BY
@@ -3473,7 +3477,7 @@ func (s SqlChannelStore) getSearchGroupChannelsQuery(userId, term string, isPost
}
var likeClauses []string
args := map[string]interface{}{"UserId": userId}
args := map[string]interface{}{"UserId": userId, "ChannelType": model.ChannelTypeGroup}
terms := strings.Split(strings.ToLower(strings.Trim(term, " ")), " ")
for idx, term := range terms {
@@ -3748,11 +3752,11 @@ func (s SqlChannelStore) GetAllChannelsForExportAfter(limit int, afterId string)
Schemes ON Channels.SchemeId = Schemes.Id
WHERE
Channels.Id > ?
AND Channels.Type IN ('O', 'P')
AND Channels.Type IN (?, ?)
ORDER BY
Id
LIMIT ?`,
afterId, limit); err != nil {
afterId, model.ChannelTypeOpen, model.ChannelTypePrivate, limit); err != nil {
return nil, errors.Wrap(err, "failed to find Channels for export")
}
@@ -3800,7 +3804,7 @@ func (s SqlChannelStore) GetAllDirectChannelsForExportAfter(limit int, afterId s
Where(sq.And{
sq.Gt{"Channels.Id": afterId},
sq.Eq{"Channels.DeleteAt": int(0)},
sq.Eq{"Channels.Type": []string{"D", "G"}},
sq.Eq{"Channels.Type": []model.ChannelType{model.ChannelTypeDirect, model.ChannelTypeGroup}},
}).
OrderBy("Channels.Id").
Limit(uint64(limit))

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

@@ -157,7 +157,7 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance, cursor model
if cursor.LastChannelsQueryPostCreateAt == 0 {
cursor.LastChannelsQueryPostCreateAt = job.StartAt
}
//append the named parameters of SQL query in the correct order to argsChannelsQuery
// append the named parameters of SQL query in the correct order to argsChannelsQuery
argsChannelsQuery = append(argsChannelsQuery, cursor.LastChannelsQueryPostCreateAt, cursor.LastChannelsQueryPostCreateAt, cursor.LastChannelsQueryPostID, job.EndAt)
argsChannelsQuery = append(argsChannelsQuery, argsEmails...)
argsChannelsQuery = append(argsChannelsQuery, argsKeywords...)
@@ -222,7 +222,7 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance, cursor model
if cursor.LastDirectMessagesQueryPostCreateAt == 0 {
cursor.LastDirectMessagesQueryPostCreateAt = job.StartAt
}
//append the named parameters of SQL query in the correct order to argsDirectMessagesQuery
// append the named parameters of SQL query in the correct order to argsDirectMessagesQuery
argsDirectMessagesQuery = append(argsDirectMessagesQuery, cursor.LastDirectMessagesQueryPostCreateAt, cursor.LastDirectMessagesQueryPostCreateAt, cursor.LastDirectMessagesQueryPostID, job.EndAt)
argsDirectMessagesQuery = append(argsDirectMessagesQuery, argsEmails...)
argsDirectMessagesQuery = append(argsDirectMessagesQuery, argsKeywords...)
@@ -285,7 +285,7 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance, cursor model
func (s SqlComplianceStore) MessageExport(cursor model.MessageExportCursor, limit int) ([]*model.MessageExport, model.MessageExportCursor, error) {
var args []interface{}
args = append(args, cursor.LastPostUpdateAt, cursor.LastPostUpdateAt, cursor.LastPostId, limit)
args = append(args, model.ChannelTypeDirect, model.ChannelTypeGroup, cursor.LastPostUpdateAt, cursor.LastPostUpdateAt, cursor.LastPostId, limit)
query :=
`SELECT
Posts.Id AS PostId,
@@ -303,8 +303,8 @@ func (s SqlComplianceStore) MessageExport(cursor model.MessageExportCursor, limi
Teams.DisplayName AS TeamDisplayName,
Channels.Id AS ChannelId,
CASE
WHEN Channels.Type = 'D' THEN 'Direct Message'
WHEN Channels.Type = 'G' THEN 'Group Message'
WHEN Channels.Type = ? THEN 'Direct Message'
WHEN Channels.Type = ? THEN 'Group Message'
ELSE Channels.DisplayName
END AS ChannelDisplayName,
Channels.Name AS ChannelName,

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

@@ -2369,7 +2369,7 @@ func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId str
sq.Eq{"p.DeleteAt": 0},
sq.Eq{"Channels.DeleteAt": 0},
sq.Eq{"Users.DeleteAt": 0},
sq.Eq{"Channels.Type": []string{"D", "G"}},
sq.Eq{"Channels.Type": []model.ChannelType{model.ChannelTypeDirect, model.ChannelTypeGroup}},
}).
OrderBy("p.Id").
Limit(uint64(limit))

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

@@ -1353,7 +1353,7 @@ func (us SqlUserStore) AnalyticsActiveCountForPeriod(startTime int64, endTime in
func (us SqlUserStore) GetUnreadCount(userId string) (int64, error) {
query := `
SELECT SUM(CASE WHEN c.Type = 'D' THEN (c.TotalMsgCount - cm.MsgCount) ELSE cm.MentionCount END)
SELECT SUM(CASE WHEN c.Type = ? THEN (c.TotalMsgCount - cm.MsgCount) ELSE cm.MentionCount END)
FROM Channels c
INNER JOIN ChannelMembers cm
ON cm.ChannelId = c.Id
@@ -1362,7 +1362,7 @@ func (us SqlUserStore) GetUnreadCount(userId string) (int64, error) {
`
var count int64
err := us.GetReplicaX().Get(&count, query, userId)
err := us.GetReplicaX().Get(&count, query, model.ChannelTypeDirect, userId)
if err != nil {
return count, errors.Wrapf(err, "failed to count unread Channels for userId=%s", userId)
}
@@ -1372,7 +1372,7 @@ func (us SqlUserStore) GetUnreadCount(userId string) (int64, error) {
func (us SqlUserStore) GetUnreadCountForChannel(userId string, channelId string) (int64, error) {
var count int64
err := us.GetReplicaX().Get(&count, "SELECT SUM(CASE WHEN c.Type = 'D' THEN (c.TotalMsgCount - cm.MsgCount) ELSE cm.MentionCount END) FROM Channels c INNER JOIN ChannelMembers cm ON c.Id = cm.ChannelId AND cm.ChannelId = ? AND cm.UserId = ?", channelId, userId)
err := us.GetReplicaX().Get(&count, "SELECT SUM(CASE WHEN c.Type = ? THEN (c.TotalMsgCount - cm.MsgCount) ELSE cm.MentionCount END) FROM Channels c INNER JOIN ChannelMembers cm ON c.Id = cm.ChannelId AND cm.ChannelId = ? AND cm.UserId = ?", model.ChannelTypeDirect, channelId, userId)
if err != nil {
return 0, errors.Wrapf(err, "failed to get unread count for channelId=%s and userId=%s", channelId, userId)
}
@@ -1733,7 +1733,7 @@ func (us SqlUserStore) GetUsersBatchForIndexing(startTime, endTime int64, limit
`).
From("ChannelMembers cm").
Join("Channels c ON cm.ChannelId = c.Id").
Where(sq.Eq{"c.Type": "O", "cm.UserId": userIds}).
Where(sq.Eq{"c.Type": model.ChannelTypeOpen, "cm.UserId": userIds}).
ToSql()
_, err = us.GetSearchReplica().Select(&channelMembers, channelMembersQuery, args...)
if err != nil {