summaryrefslogtreecommitdiffstats
path: root/store/sql_file_info_store.go
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2017-02-20 13:40:32 -0500
committerChristopher Speller <crspeller@gmail.com>2017-02-20 13:40:32 -0500
commit274b9b6032572dd33b28815a9c13bb18a02becbe (patch)
tree1fd47c65c854117d698d92b5cef701b59d4f9ebc /store/sql_file_info_store.go
parentdd4d8440eac2e4b64bfb6b449cc0668b78ecba50 (diff)
downloadchat-274b9b6032572dd33b28815a9c13bb18a02becbe.tar.gz
chat-274b9b6032572dd33b28815a9c13bb18a02becbe.tar.bz2
chat-274b9b6032572dd33b28815a9c13bb18a02becbe.zip
Fixing file info caching issue with Aurora for master (#5477)
Diffstat (limited to 'store/sql_file_info_store.go')
-rw-r--r--store/sql_file_info_store.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/store/sql_file_info_store.go b/store/sql_file_info_store.go
index 467ae39aa..bd0362db0 100644
--- a/store/sql_file_info_store.go
+++ b/store/sql_file_info_store.go
@@ -143,7 +143,7 @@ func (s SqlFileInfoStore) InvalidateFileInfosForPostCache(postId string) {
fileInfoCache.Remove(postId)
}
-func (fs SqlFileInfoStore) GetForPost(postId string, allowFromCache bool) StoreChannel {
+func (fs SqlFileInfoStore) GetForPost(postId string, readFromMaster bool, allowFromCache bool) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
@@ -174,7 +174,13 @@ func (fs SqlFileInfoStore) GetForPost(postId string, allowFromCache bool) StoreC
var infos []*model.FileInfo
- if _, err := fs.GetReplica().Select(&infos,
+ dbmap := fs.GetReplica()
+
+ if readFromMaster {
+ dbmap = fs.GetMaster()
+ }
+
+ if _, err := dbmap.Select(&infos,
`SELECT
*
FROM
@@ -187,7 +193,10 @@ func (fs SqlFileInfoStore) GetForPost(postId string, allowFromCache bool) StoreC
result.Err = model.NewLocAppError("SqlFileInfoStore.GetForPost",
"store.sql_file_info.get_for_post.app_error", nil, "post_id="+postId+", "+err.Error())
} else {
- fileInfoCache.AddWithExpiresInSecs(postId, infos, FILE_INFO_CACHE_SEC)
+ if len(infos) > 0 {
+ fileInfoCache.AddWithExpiresInSecs(postId, infos, FILE_INFO_CACHE_SEC)
+ }
+
result.Data = infos
}