MM-62900: Avoid redundant query for channelID while indexing file (#30289)

The file already has the ChannelID field. Therefore, we avoid querying
the database again. This sometimes causes errors in customer environments
where  there is noticeable replication lag, causing files not to be
indexed entirely.

https://mattermost.atlassian.net/browse/MM-62900

```release-note
NONE
```

Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
Agniva De Sarker 2025-03-20 11:46:44 +05:30 committed by GitHub
parent a51a8e9b60
commit 5609489e86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -26,15 +26,6 @@ func (s SearchFileInfoStore) indexFile(rctx request.CTX, file *model.FileInfo) {
return
}
channelId := file.ChannelId
if file.PostId != "" {
post, postErr := s.rootStore.Post().GetSingle(rctx, file.PostId, false)
if postErr != nil {
rctx.Logger().Error("Couldn't get post for file for SearchEngine indexing.", mlog.String("post_id", file.PostId), mlog.String("search_engine", engineCopy.GetName()), mlog.String("file_info_id", file.Id), mlog.Err(postErr))
return
}
channelId = post.ChannelId
}
if channelId == "" {
rctx.Logger().Error("Couldn't associate file with a channel for file for SearchEngine indexing.", mlog.String("search_engine", engineCopy.GetName()), mlog.String("file_info_id", file.Id))
return