summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/user.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/api/user.go b/api/user.go
index 4413815f9..7e5a50fc4 100644
--- a/api/user.go
+++ b/api/user.go
@@ -1251,6 +1251,7 @@ func createProfileImage(username string, userId string) ([]byte, *model.AppError
func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["user_id"]
+ readFailed := false
if result := <-Srv.Store.User().Get(id); result.Err != nil {
c.Err = result.Err
@@ -1268,15 +1269,18 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
path := "users/" + id + "/profile.png"
if data, err := ReadFile(path); err != nil {
+ readFailed = true
if img, err = createProfileImage(result.Data.(*model.User).Username, id); err != nil {
c.Err = err
return
}
- if err := WriteFile(img, path); err != nil {
- c.Err = err
- return
+ if result.Data.(*model.User).LastPictureUpdate == 0 {
+ if err := WriteFile(img, path); err != nil {
+ c.Err = err
+ return
+ }
}
} else {
@@ -1284,7 +1288,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
- if c.Session.UserId == id {
+ if c.Session.UserId == id || readFailed {
w.Header().Set("Cache-Control", "max-age=300, public") // 5 mins
} else {
w.Header().Set("Cache-Control", "max-age=86400, public") // 24 hrs