From ba627c0f922b092f4e2a12147af6a2cb49347725 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Mon, 26 Nov 2018 05:47:01 -0500 Subject: [PATCH] Skip getting the post again when getting file metadata for a post (#9879) --- api4/post.go | 2 +- app/post.go | 18 +++++++++++++----- app/post_metadata.go | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/api4/post.go b/api4/post.go index 8b1c9753a2..6fe3be51d2 100644 --- a/api4/post.go +++ b/api4/post.go @@ -528,7 +528,7 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) { return } - infos, err := c.App.GetFileInfosForPost(c.Params.PostId, false) + infos, err := c.App.GetFileInfosForPostWithMigration(c.Params.PostId) if err != nil { c.Err = err return diff --git a/app/post.go b/app/post.go index df95ebce95..97c059dcda 100644 --- a/app/post.go +++ b/app/post.go @@ -752,14 +752,13 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr return model.MakePostSearchResults(posts, nil), nil } -func (a *App) GetFileInfosForPost(postId string, readFromMaster bool) ([]*model.FileInfo, *model.AppError) { +func (a *App) GetFileInfosForPostWithMigration(postId string) ([]*model.FileInfo, *model.AppError) { pchan := a.Srv.Store.Post().GetSingle(postId) - result := <-a.Srv.Store.FileInfo().GetForPost(postId, readFromMaster, true) - if result.Err != nil { - return nil, result.Err + infos, err := a.GetFileInfosForPost(postId) + if err != nil { + return nil, err } - infos := result.Data.([]*model.FileInfo) if len(infos) == 0 { // No FileInfos were returned so check if they need to be created for this post @@ -779,6 +778,15 @@ func (a *App) GetFileInfosForPost(postId string, readFromMaster bool) ([]*model. return infos, nil } +func (a *App) GetFileInfosForPost(postId string) ([]*model.FileInfo, *model.AppError) { + result := <-a.Srv.Store.FileInfo().GetForPost(postId, false, true) + if result.Err != nil { + return nil, result.Err + } + + return result.Data.([]*model.FileInfo), nil +} + func (a *App) PostWithProxyAddedToImageURLs(post *model.Post) *model.Post { if f := a.ImageProxyAdder(); f != nil { return post.WithRewrittenImageURLs(f) diff --git a/app/post_metadata.go b/app/post_metadata.go index 9fc282c5b6..0c4df03512 100644 --- a/app/post_metadata.go +++ b/app/post_metadata.go @@ -94,7 +94,7 @@ func (a *App) getFileMetadataForPost(post *model.Post) ([]*model.FileInfo, *mode return nil, nil } - return a.GetFileInfosForPost(post.Id, false) + return a.GetFileInfosForPost(post.Id) } func (a *App) getEmojisAndReactionsForPost(post *model.Post) ([]*model.Emoji, []*model.Reaction, *model.AppError) {