mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
Fix cache to be per user.
This commit is contained in:
parent
4b8dd172ab
commit
680475d466
@ -73,9 +73,8 @@ func (h *SummaryHandler) Get(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var summary *models.Summary
|
var summary *models.Summary
|
||||||
cacheKey := getHash([]time.Time{from, to})
|
cacheKey := getHash([]time.Time{from, to}, user)
|
||||||
cachedSummary, ok := h.Cache.Get(cacheKey)
|
if cachedSummary, ok := h.Cache.Get(cacheKey); !ok {
|
||||||
if !ok {
|
|
||||||
// Cache Miss
|
// Cache Miss
|
||||||
summary, err = h.SummarySrvc.GetSummary(from, to, user) // 'to' is always constant
|
summary, err = h.SummarySrvc.GetSummary(from, to, user) // 'to' is always constant
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -92,10 +91,11 @@ func (h *SummaryHandler) Get(w http.ResponseWriter, r *http.Request) {
|
|||||||
utils.RespondJSON(w, http.StatusOK, summary)
|
utils.RespondJSON(w, http.StatusOK, summary)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHash(times []time.Time) string {
|
func getHash(times []time.Time, user *models.User) string {
|
||||||
digest := md5.New()
|
digest := md5.New()
|
||||||
for _, t := range times {
|
for _, t := range times {
|
||||||
digest.Write([]byte(strconv.Itoa(int(t.Unix()))))
|
digest.Write([]byte(strconv.Itoa(int(t.Unix()))))
|
||||||
}
|
}
|
||||||
|
digest.Write([]byte(user.ID))
|
||||||
return string(digest.Sum(nil))
|
return string(digest.Sum(nil))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user