diff options
author | Corey Hulen <corey@hulen.com> | 2017-02-15 18:54:41 -0500 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-02-15 18:54:41 -0500 |
commit | 1d6ea40022b3806d405ae29c77096300f0c94932 (patch) | |
tree | 68b78ca45fcd149895bd53c23f8d69ae027a03d2 /api | |
parent | db2966b7cb3111ff1b3cadfbec1221343b0e8629 (diff) | |
download | chat-1d6ea40022b3806d405ae29c77096300f0c94932.tar.gz chat-1d6ea40022b3806d405ae29c77096300f0c94932.tar.bz2 chat-1d6ea40022b3806d405ae29c77096300f0c94932.zip |
Adding caching to profile images to master (#5428)
* Adding caching to profile images
* Fixing break
* Adding back in failed read
* Fixing build break
* Fixing break
Diffstat (limited to 'api')
-rw-r--r-- | api/user.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/api/user.go b/api/user.go index dff851322..cdb8f4f3e 100644 --- a/api/user.go +++ b/api/user.go @@ -590,26 +590,33 @@ func getAudits(c *Context, w http.ResponseWriter, r *http.Request) { func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) id := params["user_id"] + readFailed := false var etag string - if user, err := app.GetUser(id); err != nil { + if users, err := app.GetUsersByIds([]string{id}, false); err != nil { c.Err = err return } else { + if len(users) == 0 { + c.Err = model.NewLocAppError("getProfileImage", "store.sql_user.get_profiles.app_error", nil, "") + return + } + + user := users[0] etag = strconv.FormatInt(user.LastPictureUpdate, 10) if HandleEtag(etag, "Profile Image", w, r) { return } var img []byte - img, err = app.GetProfileImage(user) + img, readFailed, err = app.GetProfileImage(user) if err != nil { c.Err = err return } - if c.Session.UserId == id { + if readFailed { w.Header().Set("Cache-Control", "max-age=300, public") // 5 mins } else { w.Header().Set("Cache-Control", "max-age=86400, public") // 24 hrs |