Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
c68e7c72
Commit
c68e7c72
authored
Dec 07, 2017
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avatar: avoid concurrent map writes
parent
ea2f65b4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
4 deletions
+8
-4
pkg/api/avatar/avatar.go
+8
-4
No files found.
pkg/api/avatar/avatar.go
View file @
c68e7c72
...
@@ -25,6 +25,8 @@ import (
...
@@ -25,6 +25,8 @@ import (
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/setting"
"gopkg.in/macaron.v1"
"gopkg.in/macaron.v1"
gocache
"github.com/patrickmn/go-cache"
)
)
var
gravatarSource
string
var
gravatarSource
string
...
@@ -92,7 +94,7 @@ func (this *Avatar) Update() (err error) {
...
@@ -92,7 +94,7 @@ func (this *Avatar) Update() (err error) {
type
CacheServer
struct
{
type
CacheServer
struct
{
notFound
*
Avatar
notFound
*
Avatar
cache
map
[
string
]
*
Avatar
cache
*
gocache
.
Cache
}
}
func
(
this
*
CacheServer
)
mustInt
(
r
*
http
.
Request
,
defaultValue
int
,
keys
...
string
)
(
v
int
)
{
func
(
this
*
CacheServer
)
mustInt
(
r
*
http
.
Request
,
defaultValue
int
,
keys
...
string
)
(
v
int
)
{
...
@@ -110,7 +112,9 @@ func (this *CacheServer) Handler(ctx *macaron.Context) {
...
@@ -110,7 +112,9 @@ func (this *CacheServer) Handler(ctx *macaron.Context) {
var
avatar
*
Avatar
var
avatar
*
Avatar
if
avatar
,
_
=
this
.
cache
[
hash
];
avatar
==
nil
{
if
obj
,
exist
:=
this
.
cache
.
Get
(
hash
);
exist
{
avatar
=
obj
.
(
*
Avatar
)
}
else
{
avatar
=
New
(
hash
)
avatar
=
New
(
hash
)
}
}
...
@@ -124,7 +128,7 @@ func (this *CacheServer) Handler(ctx *macaron.Context) {
...
@@ -124,7 +128,7 @@ func (this *CacheServer) Handler(ctx *macaron.Context) {
if
avatar
.
notFound
{
if
avatar
.
notFound
{
avatar
=
this
.
notFound
avatar
=
this
.
notFound
}
else
{
}
else
{
this
.
cache
[
hash
]
=
avatar
this
.
cache
.
Add
(
hash
,
avatar
,
gocache
.
DefaultExpiration
)
}
}
ctx
.
Resp
.
Header
()
.
Add
(
"Content-Type"
,
"image/jpeg"
)
ctx
.
Resp
.
Header
()
.
Add
(
"Content-Type"
,
"image/jpeg"
)
...
@@ -146,7 +150,7 @@ func NewCacheServer() *CacheServer {
...
@@ -146,7 +150,7 @@ func NewCacheServer() *CacheServer {
return
&
CacheServer
{
return
&
CacheServer
{
notFound
:
newNotFound
(),
notFound
:
newNotFound
(),
cache
:
make
(
map
[
string
]
*
Avatar
),
cache
:
gocache
.
New
(
time
.
Hour
,
time
.
Hour
*
2
),
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment