From 487bb56a9b8f5c7a9efaabfc631f2f6c689ef74b Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Tue, 7 Feb 2017 12:36:37 -0800 Subject: Add caching for file infos (#5330) --- app/file.go | 2 +- app/notification.go | 4 ++-- app/post.go | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/file.go b/app/file.go index 4ddf7ac2d..095e4d032 100644 --- a/app/file.go +++ b/app/file.go @@ -318,7 +318,7 @@ func MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo { return []*model.FileInfo{} } else if newPost := result.Data.(*model.PostList).Posts[post.Id]; len(newPost.Filenames) != len(post.Filenames) { // Another thread has already created FileInfos for this post, so just return those - if result := <-Srv.Store.FileInfo().GetForPost(post.Id); result.Err != nil { + if result := <-Srv.Store.FileInfo().GetForPost(post.Id, false); result.Err != nil { l4g.Error(utils.T("api.file.migrate_filenames_to_file_infos.get_post_file_infos_again.app_error"), post.Id, result.Err) return []*model.FileInfo{} } else { diff --git a/app/notification.go b/app/notification.go index cc4e13ab1..1550c0393 100644 --- a/app/notification.go +++ b/app/notification.go @@ -26,7 +26,7 @@ import ( func SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User) ([]string, *model.AppError) { pchan := Srv.Store.User().GetAllProfilesInChannel(channel.Id, true) - fchan := Srv.Store.FileInfo().GetForPost(post.Id) + fchan := Srv.Store.FileInfo().GetForPost(post.Id, true) var profileMap map[string]*model.User if result := <-pchan; result.Err != nil { @@ -414,7 +414,7 @@ func GetMessageForNotification(post *model.Post, translateFunc i18n.TranslateFun // extract the filenames from their paths and determine what type of files are attached var infos []*model.FileInfo - if result := <-Srv.Store.FileInfo().GetForPost(post.Id); result.Err != nil { + if result := <-Srv.Store.FileInfo().GetForPost(post.Id, true); result.Err != nil { l4g.Warn(utils.T("api.post.get_message_for_notification.get_files.error"), post.Id, result.Err) } else { infos = result.Data.([]*model.FileInfo) diff --git a/app/post.go b/app/post.go index 82fc733b4..5fddd3e78 100644 --- a/app/post.go +++ b/app/post.go @@ -457,7 +457,7 @@ func SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bo func GetFileInfosForPost(postId string) ([]*model.FileInfo, *model.AppError) { pchan := Srv.Store.Post().Get(postId) - fchan := Srv.Store.FileInfo().GetForPost(postId) + fchan := Srv.Store.FileInfo().GetForPost(postId, true) var infos []*model.FileInfo if result := <-fchan; result.Err != nil { @@ -476,6 +476,7 @@ func GetFileInfosForPost(postId string) ([]*model.FileInfo, *model.AppError) { } if len(post.Filenames) > 0 { + Srv.Store.FileInfo().InvalidateFileInfosForPostCache(postId) // The post has Filenames that need to be replaced with FileInfos infos = MigrateFilenamesToFileInfos(post) } -- cgit v1.2.3-1-g7c22