[MM-46516] P1 - Fix total message counting for top DM (#20858)

Automatic Merge
Этот коммит содержится в:
Shivashis Padhi
2022-09-07 04:04:01 +05:30
коммит произвёл GitHub
родитель d23c7ed2a3
Коммит 8f743c37b6
2 изменённых файлов: 11 добавлений и 2 удалений

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

@@ -3009,7 +3009,7 @@ func (s *SqlPostStore) GetTopDMsForUserSince(userID string, since int64, offset
aggregator = "string_agg(distinct cm.UserId, ',') as Participants" aggregator = "string_agg(distinct cm.UserId, ',') as Participants"
} }
topDMsBuilder := s.getQueryBuilder().Select("vch.TotalMsgCount as MessageCount", aggregator, "vch.Id as ChannelId").FromSelect(channelSelector, "vch"). topDMsBuilder := s.getQueryBuilder().Select("count(p.Id) as MessageCount", aggregator, "vch.Id as ChannelId").FromSelect(channelSelector, "vch").
Join("ChannelMembers as cm on cm.ChannelId = vch.Id"). Join("ChannelMembers as cm on cm.ChannelId = vch.Id").
Join("Posts as p on p.ChannelId = vch.Id"). Join("Posts as p on p.ChannelId = vch.Id").
Where(sq.And{ Where(sq.And{
@@ -3019,7 +3019,7 @@ func (s *SqlPostStore) GetTopDMsForUserSince(userID string, since int64, offset
sq.Eq{ sq.Eq{
"p.DeleteAt": 0, "p.DeleteAt": 0,
}, },
}).GroupBy("vch.id", "vch.TotalMsgCount") }).GroupBy("vch.id")
topDMsBuilder = topDMsBuilder.OrderBy("MessageCount DESC").Limit(uint64(limit + 1)).Offset(uint64(offset)) topDMsBuilder = topDMsBuilder.OrderBy("MessageCount DESC").Limit(uint64(limit + 1)).Offset(uint64(offset))
@@ -3054,6 +3054,8 @@ func postProcessTopDMs(s *SqlPostStore, userID string, topDMs []*model.TopDM, si
// channel with self // channel with self
secondParticipantId = "-1" secondParticipantId = "-1"
} else { } else {
// divide message count by 2, because it's counted twice due to channel memberships being 2 for dms.
topDM.MessageCount = topDM.MessageCount / 2
if participants[0] == userID { if participants[0] == userID {
secondParticipantId = participants[1] secondParticipantId = participants[1]
} else { } else {

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

@@ -4106,6 +4106,13 @@ func testGetTopDMsForUserSince(t *testing.T, ss store.Store, s SqlStore) {
UserId: u2.Id, UserId: u2.Id,
}) })
require.NoError(t, err) require.NoError(t, err)
// create second post for u2: modify create at to a very old date to make sure it isn't counted
_, err = ss.Post().Save(&model.Post{
ChannelId: chUser2.Id,
UserId: u2.Id,
CreateAt: 100,
})
require.NoError(t, err)
// for user-u3: 3 posts // for user-u3: 3 posts
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
_, err = ss.Post().Save(&model.Post{ _, err = ss.Post().Save(&model.Post{