fix bug rendering sf useless
This commit is contained in:
parent
085490e92b
commit
c880f0b80f
1 changed files with 6 additions and 6 deletions
|
@ -17,10 +17,10 @@ type ProtectedContent struct {
|
||||||
ClaimID string `json:"claim_id"`
|
ClaimID string `json:"claim_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var blockedCache = gcache.New(10).Expiration(2 * time.Minute).Build()
|
var protectedCache = gcache.New(10).Expiration(2 * time.Minute).Build()
|
||||||
|
|
||||||
func GetBlockedContent() (map[string]bool, error) {
|
func GetProtectedContent() (map[string]bool, error) {
|
||||||
cachedVal, err := blockedCache.Get("protected")
|
cachedVal, err := protectedCache.Get("protected")
|
||||||
if err == nil && cachedVal != nil {
|
if err == nil && cachedVal != nil {
|
||||||
return cachedVal.(map[string]bool), nil
|
return cachedVal.(map[string]bool), nil
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ func GetBlockedContent() (map[string]bool, error) {
|
||||||
for _, pc := range r.Data {
|
for _, pc := range r.Data {
|
||||||
protectedMap[pc.SDHash] = true
|
protectedMap[pc.SDHash] = true
|
||||||
}
|
}
|
||||||
err = blockedCache.Set("protected", protectedMap)
|
err = protectedCache.Set("protected", protectedMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return protectedMap, errors.Err(err)
|
return protectedMap, errors.Err(err)
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,8 @@ func GetBlockedContent() (map[string]bool, error) {
|
||||||
var sf = singleflight.Group{}
|
var sf = singleflight.Group{}
|
||||||
|
|
||||||
func IsProtected(sdHash string) bool {
|
func IsProtected(sdHash string) bool {
|
||||||
val, err, _ := sf.Do(sdHash, func() (interface{}, error) {
|
val, err, _ := sf.Do("protected", func() (interface{}, error) {
|
||||||
protectedMap, err := GetBlockedContent()
|
protectedMap, err := GetProtectedContent()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue