[MM-42742] Add top reactions endpoint (#19850)
Этот коммит содержится в:
@@ -228,6 +228,121 @@ func (s *SqlReactionStore) PermanentDeleteBatch(endTime int64, limit int64) (int
|
||||
return rowsAffected, nil
|
||||
}
|
||||
|
||||
// GetTopForTeamSince returns the instance counts of the following Reactions sets:
|
||||
// a) those created by anyone in private channels in the given user's membership graph on the given team, and
|
||||
// b) those created by anyone in public channels on the given team.
|
||||
func (s *SqlReactionStore) GetTopForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopReactionList, error) {
|
||||
var reactions []*model.TopReaction
|
||||
|
||||
query := `
|
||||
SELECT
|
||||
EmojiName,
|
||||
sum(EmojiCount) AS Count
|
||||
FROM ((
|
||||
SELECT
|
||||
EmojiName,
|
||||
count(EmojiName) AS EmojiCount
|
||||
FROM
|
||||
ChannelMembers
|
||||
INNER JOIN Channels ON ChannelMembers.ChannelId = Channels.Id
|
||||
INNER JOIN Posts ON Channels.Id = Posts.ChannelId
|
||||
INNER JOIN Reactions ON Posts.Id = Reactions.PostId
|
||||
WHERE
|
||||
Reactions.DeleteAt = 0
|
||||
AND ChannelMembers.UserId = ?
|
||||
AND Channels.Type = 'P'
|
||||
AND Channels.TeamId = ?
|
||||
AND Reactions.CreateAt > ?
|
||||
GROUP BY
|
||||
Reactions.EmojiName)
|
||||
UNION ALL (
|
||||
SELECT
|
||||
EmojiName,
|
||||
count(EmojiName) AS EmojiCount
|
||||
FROM
|
||||
Reactions
|
||||
INNER JOIN Posts ON Reactions.PostId = Posts.Id
|
||||
INNER JOIN Channels ON Posts.ChannelId = Channels.Id
|
||||
WHERE
|
||||
Reactions.DeleteAt = 0
|
||||
AND Channels.Type = 'O'
|
||||
AND Channels.TeamId = ?
|
||||
AND Reactions.CreateAt > ?
|
||||
GROUP BY
|
||||
Reactions.EmojiName)) AS A
|
||||
GROUP BY
|
||||
EmojiName
|
||||
ORDER BY
|
||||
Count DESC,
|
||||
EmojiName ASC
|
||||
LIMIT ?
|
||||
OFFSET ?`
|
||||
|
||||
if err := s.GetReplicaX().Select(&reactions, query, userID, teamID, since, teamID, since, limit+1, offset); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get top Reactions")
|
||||
}
|
||||
|
||||
return model.GetTopReactionListWithRankAndPagination(reactions, limit, offset), nil
|
||||
}
|
||||
|
||||
// GetTopForUserSince returns the instance counts of the following Reactions sets:
|
||||
// a) those created by the given user in any channel type on the given team (across the workspace if no team is given), and
|
||||
// b) those created by the given user in DM or group channels.
|
||||
func (s *SqlReactionStore) GetTopForUserSince(userID string, teamID string, since int64, offset int, limit int) (*model.TopReactionList, error) {
|
||||
var reactions []*model.TopReaction
|
||||
var args []interface{}
|
||||
var query string
|
||||
|
||||
if teamID != "" {
|
||||
query = `
|
||||
SELECT
|
||||
EmojiName,
|
||||
count(EmojiName) AS Count
|
||||
FROM
|
||||
Reactions
|
||||
INNER JOIN Posts ON Reactions.PostId = Posts.Id
|
||||
INNER JOIN Channels ON Posts.ChannelId = Channels.Id
|
||||
WHERE
|
||||
Reactions.DeleteAt = 0
|
||||
AND Reactions.UserId = ?
|
||||
AND (Channels.TeamId = ? OR Channels.Type = 'D' OR Channels.Type = 'G')
|
||||
AND Reactions.CreateAt > ?
|
||||
GROUP BY
|
||||
EmojiName
|
||||
ORDER BY
|
||||
Count DESC,
|
||||
EmojiName ASC
|
||||
LIMIT ?
|
||||
OFFSET ?`
|
||||
args = []interface{}{userID, teamID, since, limit + 1, offset}
|
||||
} else {
|
||||
query = `
|
||||
SELECT
|
||||
EmojiName,
|
||||
count(EmojiName) AS Count
|
||||
FROM
|
||||
Reactions
|
||||
WHERE
|
||||
Reactions.DeleteAt = 0
|
||||
AND Reactions.UserId = ?
|
||||
AND Reactions.CreateAt > ?
|
||||
GROUP BY
|
||||
Reactions.EmojiName
|
||||
ORDER BY
|
||||
Count DESC,
|
||||
EmojiName ASC
|
||||
LIMIT ?
|
||||
OFFSET ?`
|
||||
args = []interface{}{userID, since, limit + 1, offset}
|
||||
}
|
||||
|
||||
if err := s.GetReplicaX().Select(&reactions, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get top Reactions")
|
||||
}
|
||||
|
||||
return model.GetTopReactionListWithRankAndPagination(reactions, limit, offset), nil
|
||||
}
|
||||
|
||||
func (s *SqlReactionStore) saveReactionAndUpdatePost(transaction *sqlxTxWrapper, reaction *model.Reaction) error {
|
||||
reaction.DeleteAt = 0
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user