[MM-46603] P1 - Improvements in handling '0 posts' channels (#20905)
Automatic Merge
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
42e03e18b9
Коммит
38aaa9e3d3
@@ -4337,48 +4337,45 @@ func (s SqlChannelStore) GetTopInactiveChannelsForTeamSince(teamID string, userI
|
||||
LastActivityAt
|
||||
FROM
|
||||
((SELECT
|
||||
Posts.ChannelId AS ID,
|
||||
PublicChannels.Id AS ID,
|
||||
'O' AS Type,
|
||||
PublicChannels.DisplayName AS DisplayName,
|
||||
PublicChannels.Name AS Name,
|
||||
count(Posts.Id) AS MessageCount,
|
||||
max(Posts.CreateAt) AS LastActivityAt
|
||||
COALESCE(count(Posts.Id), 0) AS MessageCount,
|
||||
COALESCE(max(Posts.CreateAt), 0) AS LastActivityAt
|
||||
FROM
|
||||
Posts
|
||||
LEFT JOIN PublicChannels on Posts.ChannelId = PublicChannels.Id
|
||||
PublicChannels
|
||||
LEFT JOIN Posts on Posts.ChannelId = PublicChannels.Id AND Posts.Type = '' AND Posts.CreateAt > ? AND Posts.DeleteAt = 0
|
||||
LEFT JOIN Channels on Channels.Id = PublicChannels.Id
|
||||
WHERE
|
||||
Posts.DeleteAt = 0
|
||||
AND Posts.CreateAt > ?
|
||||
AND (Posts.Type = '' OR Posts.Type = 'system_join_channel')
|
||||
AND PublicChannels.TeamId = ?
|
||||
PublicChannels.TeamId = ?
|
||||
AND PublicChannels.DeleteAt = 0
|
||||
AND Channels.CreateAt < ?
|
||||
GROUP BY
|
||||
Posts.ChannelId,
|
||||
PublicChannels.Id,
|
||||
PublicChannels.DisplayName,
|
||||
PublicChannels.Name,
|
||||
PublicChannels.TeamId)
|
||||
UNION ALL
|
||||
(SELECT
|
||||
Posts.ChannelId AS ID,
|
||||
Channels.Id AS ID,
|
||||
Channels.Type AS Type,
|
||||
Channels.DisplayName AS DisplayName,
|
||||
Channels.Name AS Name,
|
||||
count(Posts.Id) AS MessageCount,
|
||||
max(Posts.CreateAt) AS LastActivityAt
|
||||
COALESCE(count(Posts.Id), 0) AS MessageCount,
|
||||
COALESCE(max(Posts.CreateAt), 0) AS LastActivityAt
|
||||
FROM
|
||||
Posts
|
||||
LEFT JOIN Channels on Posts.ChannelId = Channels.Id
|
||||
Channels
|
||||
LEFT JOIN Posts on Posts.ChannelId = Channels.Id AND Posts.Type = '' AND Posts.CreateAt > ? AND Posts.DeleteAt = 0
|
||||
LEFT JOIN ChannelMembers on Posts.ChannelId = ChannelMembers.ChannelId
|
||||
WHERE
|
||||
Posts.DeleteAt = 0
|
||||
AND Posts.CreateAt > ?
|
||||
AND (Posts.Type = '' OR Posts.Type = 'system_join_channel')
|
||||
AND Channels.TeamId = ?
|
||||
Channels.TeamId = ?
|
||||
AND Channels.CreateAt < ?
|
||||
AND Channels.Type = 'P'
|
||||
AND Channels.DeleteAt = 0
|
||||
AND ChannelMembers.UserId = ?
|
||||
GROUP BY
|
||||
Posts.ChannelId,
|
||||
Channels.Id,
|
||||
Channels.Type,
|
||||
Channels.DisplayName,
|
||||
Channels.Name)) AS A
|
||||
@@ -4387,8 +4384,7 @@ func (s SqlChannelStore) GetTopInactiveChannelsForTeamSince(teamID string, userI
|
||||
Name ASC
|
||||
LIMIT ?
|
||||
OFFSET ?`
|
||||
args = append(args, since, teamID, since, teamID, userID, limit+1, offset)
|
||||
|
||||
args = append(args, since, teamID, since, since, teamID, since, userID, limit+1, offset)
|
||||
if err := s.GetReplicaX().Select(&channels, query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get top Channels")
|
||||
}
|
||||
@@ -4411,25 +4407,23 @@ func (s SqlChannelStore) GetTopInactiveChannelsForUserSince(teamID string, userI
|
||||
|
||||
query = `
|
||||
SELECT
|
||||
Posts.ChannelId AS ID,
|
||||
Channels.Id AS ID,
|
||||
Channels.Type AS Type,
|
||||
Channels.DisplayName AS DisplayName,
|
||||
Channels.Name AS Name,
|
||||
count(Posts.Id) AS MessageCount,
|
||||
max(Posts.CreateAt) AS LastActivityAt
|
||||
COALESCE(count(Posts.Id), 0) AS MessageCount,
|
||||
COALESCE(max(Posts.CreateAt), 0) AS LastActivityAt
|
||||
FROM
|
||||
Posts
|
||||
LEFT JOIN Channels on Posts.ChannelId = Channels.Id
|
||||
Channels
|
||||
LEFT JOIN Posts on Posts.ChannelId = Channels.Id AND Posts.Type = '' AND Posts.CreateAt > ? AND Posts.DeleteAt = 0
|
||||
LEFT JOIN ChannelMembers on Posts.ChannelId = ChannelMembers.ChannelId
|
||||
WHERE
|
||||
Posts.DeleteAt = 0
|
||||
AND Posts.CreateAt > ?
|
||||
AND (Posts.Type = '' OR Posts.Type = 'system_join_channel')
|
||||
AND Channels.DeleteAt = 0
|
||||
Channels.DeleteAt = 0
|
||||
AND Channels.CreateAt < ?
|
||||
AND (Channels.Type = 'O' OR Channels.Type = 'P')
|
||||
AND ChannelMembers.UserId = ? `
|
||||
|
||||
args = []any{since, userID}
|
||||
args = []any{since, since, userID}
|
||||
|
||||
if teamID != "" {
|
||||
query += `
|
||||
@@ -4439,7 +4433,7 @@ func (s SqlChannelStore) GetTopInactiveChannelsForUserSince(teamID string, userI
|
||||
|
||||
query += `
|
||||
Group By
|
||||
Posts.ChannelId,
|
||||
Channels.Id,
|
||||
Channels.Type,
|
||||
Channels.DisplayName,
|
||||
Channels.Name
|
||||
|
||||
@@ -7978,6 +7978,7 @@ func testGetTopInactiveChannels(t *testing.T, ss store.Store) {
|
||||
DisplayName: "test_share_flag asdf",
|
||||
Name: "test_share_flag_public0",
|
||||
Type: model.ChannelTypeOpen,
|
||||
CreateAt: 1,
|
||||
}
|
||||
|
||||
channelSaved0, err := ss.Channel().Save(channelPublic0, 999)
|
||||
@@ -7989,6 +7990,7 @@ func testGetTopInactiveChannels(t *testing.T, ss store.Store) {
|
||||
DisplayName: "test_share_flag",
|
||||
Name: "test_share_flag",
|
||||
Type: model.ChannelTypeOpen,
|
||||
CreateAt: 1,
|
||||
}
|
||||
|
||||
channelSaved1, err := ss.Channel().Save(channelPublic1, 999)
|
||||
@@ -8001,6 +8003,7 @@ func testGetTopInactiveChannels(t *testing.T, ss store.Store) {
|
||||
c3.DisplayName = "Channel3" + model.NewId()
|
||||
c3.Name = NewTestId()
|
||||
c3.Type = model.ChannelTypePrivate
|
||||
c3.CreateAt = 1
|
||||
channelPrivate, nErr := ss.Channel().Save(&c3, -1)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
@@ -8080,7 +8083,7 @@ func testGetTopInactiveChannels(t *testing.T, ss store.Store) {
|
||||
|
||||
// for u1
|
||||
t.Run("top inactive channels for team - u1 ", func(t *testing.T) {
|
||||
topInactiveChannels, err := ss.Channel().GetTopInactiveChannelsForTeamSince(team.Id, u1.Id, 0, 0, 10)
|
||||
topInactiveChannels, err := ss.Channel().GetTopInactiveChannelsForTeamSince(team.Id, u1.Id, 2, 0, 10)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, topInactiveChannels.Items, 3)
|
||||
require.Equal(t, topInactiveChannels.Items[0].ID, channelSaved0.Id)
|
||||
@@ -8096,7 +8099,7 @@ func testGetTopInactiveChannels(t *testing.T, ss store.Store) {
|
||||
})
|
||||
|
||||
t.Run("top inactive channels for user - u1 ", func(t *testing.T) {
|
||||
topInactiveChannels, err := ss.Channel().GetTopInactiveChannelsForUserSince(team.Id, u1.Id, 0, 0, 10)
|
||||
topInactiveChannels, err := ss.Channel().GetTopInactiveChannelsForUserSince(team.Id, u1.Id, 2, 0, 10)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, topInactiveChannels.Items, 2)
|
||||
require.Equal(t, topInactiveChannels.Items[0].ID, channelPrivate.Id)
|
||||
@@ -8105,7 +8108,7 @@ func testGetTopInactiveChannels(t *testing.T, ss store.Store) {
|
||||
|
||||
// for u2
|
||||
t.Run("top inactive channels for team - u2 ", func(t *testing.T) {
|
||||
topInactiveChannels, err := ss.Channel().GetTopInactiveChannelsForTeamSince(team.Id, u2.Id, 0, 0, 10)
|
||||
topInactiveChannels, err := ss.Channel().GetTopInactiveChannelsForTeamSince(team.Id, u2.Id, 2, 0, 10)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, topInactiveChannels.Items, 2)
|
||||
require.Equal(t, topInactiveChannels.Items[0].ID, channelSaved0.Id)
|
||||
@@ -8114,7 +8117,7 @@ func testGetTopInactiveChannels(t *testing.T, ss store.Store) {
|
||||
})
|
||||
|
||||
t.Run("top inactive channels for user - u2 ", func(t *testing.T) {
|
||||
topInactiveChannels, err := ss.Channel().GetTopInactiveChannelsForUserSince(team.Id, u2.Id, 0, 0, 10)
|
||||
topInactiveChannels, err := ss.Channel().GetTopInactiveChannelsForUserSince(team.Id, u2.Id, 2, 0, 10)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, topInactiveChannels.Items, 1)
|
||||
require.Equal(t, topInactiveChannels.Items[0].ID, channelPublic0.Id)
|
||||
|
||||
Ссылка в новой задаче
Block a user