From a5ea445bf9b173515f09a4b71a15c911cf9f35cb Mon Sep 17 00:00:00 2001 From: Julien Tant <785518+JulienTant@users.noreply.github.com> Date: Tue, 30 Aug 2022 09:49:39 -0700 Subject: [PATCH] [MM-46097] Change FileInfo count query (#20871) Co-authored-by: Mattermod --- store/sqlstore/channel_store.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index 51e6fb6f3f..e772f2706d 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -2213,14 +2213,13 @@ func (s SqlChannelStore) GetFileCount(channelId string) (int64, error) { var count int64 err := s.GetReplicaX().Get(&count, ` SELECT - COUNT(*) + COUNT(*) FROM - FileInfo - LEFT JOIN Posts as P ON FileInfo.PostId=P.Id - LEFT JOIN Channels as C on C.Id=P.ChannelId + FileInfo WHERE - FileInfo.DeleteAt = 0 - AND C.Id = ?`, channelId) + FileInfo.DeleteAt = 0 + AND FileInfo.PostId IN (SELECT id FROM Posts WHERE ChannelId = ?)`, + channelId) if err != nil { return 0, errors.Wrapf(err, "failed to count files with channelId=%s", channelId) }