From 1d6ea40022b3806d405ae29c77096300f0c94932 Mon Sep 17 00:00:00 2001 From: Corey Hulen Date: Wed, 15 Feb 2017 18:54:41 -0500 Subject: 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 --- api/user.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'api') 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 -- cgit v1.2.3-1-g7c22