fixed channel counts etag to only update when appropriate

Этот коммит содержится в:
JoramWilander
2015-08-11 10:54:26 -04:00
родитель cb17851e2d
Коммит 3f38c21796
2 изменённых файлов: 13 добавлений и 4 удалений

Просмотреть файл

@@ -422,7 +422,7 @@ func TestGetChannelCounts(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} else if cache_result.Data.(*model.ChannelCounts) != nil { } else if cache_result.Data.(*model.ChannelCounts) != nil {
t.Log(cache_result.Data) t.Log(cache_result.Data)
t.Fatal("cache should be empty") t.Fatal("result data should be empty")
} }
} }

Просмотреть файл

@@ -6,7 +6,9 @@ package model
import ( import (
"crypto/md5" "crypto/md5"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"sort"
"strconv" "strconv"
) )
@@ -16,12 +18,19 @@ type ChannelCounts struct {
} }
func (o *ChannelCounts) Etag() string { func (o *ChannelCounts) Etag() string {
ids := []string{}
for id, _ := range o.Counts {
ids = append(ids, id)
}
sort.Strings(ids)
str := "" str := ""
for id, count := range o.Counts { for _, id := range ids {
str += id + strconv.FormatInt(count, 10) str += id + strconv.FormatInt(o.Counts[id], 10)
} }
md5Counts := md5.Sum([]byte(str)) md5Counts := fmt.Sprintf("%x", md5.Sum([]byte(str)))
var update int64 = 0 var update int64 = 0
for _, u := range o.UpdateTimes { for _, u := range o.UpdateTimes {