From d6c11d1d2696827ca87acad8ba83affc01f5f231 Mon Sep 17 00:00:00 2001 From: Caleb Roseland Date: Thu, 19 Sep 2024 04:57:10 -0500 Subject: [PATCH] get channel id for bookmark files in ES/OS (#28221) Co-authored-by: Miguel de la Cruz --- .../store/searchlayer/file_info_layer.go | 19 ++++++++++++++----- .../store/searchtest/file_info_layer.go | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/server/channels/store/searchlayer/file_info_layer.go b/server/channels/store/searchlayer/file_info_layer.go index ce72a97f0e..d6ccd89029 100644 --- a/server/channels/store/searchlayer/file_info_layer.go +++ b/server/channels/store/searchlayer/file_info_layer.go @@ -20,16 +20,25 @@ func (s SearchFileInfoStore) indexFile(rctx request.CTX, file *model.FileInfo) { for _, engine := range s.rootStore.searchEngine.GetActiveEngines() { if engine.IsIndexingEnabled() { runIndexFn(rctx, engine, func(engineCopy searchengine.SearchEngineInterface) { - if file.PostId == "" { + if file.PostId == "" && file.CreatorId != model.BookmarkFileOwner { return } - 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)) + 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 } - if err := engineCopy.IndexFile(file, post.ChannelId); err != nil { + if err := engineCopy.IndexFile(file, channelId); err != nil { rctx.Logger().Error("Encountered error indexing file", mlog.String("file_info_id", file.Id), mlog.String("search_engine", engineCopy.GetName()), mlog.Err(err)) return } diff --git a/server/channels/store/searchtest/file_info_layer.go b/server/channels/store/searchtest/file_info_layer.go index cf21046ef6..ccee5750f6 100644 --- a/server/channels/store/searchtest/file_info_layer.go +++ b/server/channels/store/searchtest/file_info_layer.go @@ -191,7 +191,7 @@ var searchFileInfoStoreTests = []searchTest{ { Name: "Should search files part of channel bookmarks", Fn: testFileInfoSearchShowChannelBookmarkFiles, - Tags: []string{EnginePostgres, EngineMySQL}, + Tags: []string{EnginePostgres, EngineMySQL, EngineElasticSearch}, }, }