From 0ffcf653c96fb6353a3fc098273ebab76ff14748 Mon Sep 17 00:00:00 2001 From: mlabusch Date: Fri, 12 May 2017 11:50:51 +0200 Subject: [PATCH] [TASK] change traffic lights to be better seen --- contrib/good_availablity.svg | 12 ++++-------- contrib/good_freshness.svg | 4 ++-- http/good_show.go | 2 +- runtime/auth.go | 8 +++++++- runtime/productcache.go | 4 ++++ webroot/static/html/item.html | 3 +-- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/contrib/good_availablity.svg b/contrib/good_availablity.svg index 67d577d..ca93384 100644 --- a/contrib/good_availablity.svg +++ b/contrib/good_availablity.svg @@ -5,15 +5,11 @@ - {{if lt .Count 4}} - - - {{ else if and (lt .Count 7) (gt .Count 3)}} - - + {{if eq .Count 0}} + {{else}} - - + + {{end}} {{.Count}} diff --git a/contrib/good_freshness.svg b/contrib/good_freshness.svg index 5f807f1..cdd2a79 100644 --- a/contrib/good_freshness.svg +++ b/contrib/good_freshness.svg @@ -2,9 +2,9 @@ {{if eq .Fresh false}} - + {{else}} - + {{end}} diff --git a/http/good_show.go b/http/good_show.go index d10b157..8fd85bc 100644 --- a/http/good_show.go +++ b/http/good_show.go @@ -101,7 +101,7 @@ func getGoodFreshness(w http.ResponseWriter, r *http.Request){ } fresh := false if good.FouledAt != nil { - fresh = time.Now().Add(-time.Duration(3) * time.Hour * 24).Before(*good.FouledAt) + fresh = time.Now().Before(*good.FouledAt) } log = log.WithField("type", r.Header.Get("Content-Type")) diff --git a/runtime/auth.go b/runtime/auth.go index 262b8f7..d3ea215 100644 --- a/runtime/auth.go +++ b/runtime/auth.go @@ -7,6 +7,7 @@ import ( "time" "github.com/genofire/hs_master-kss-monolith/lib/log" + "sync" ) // URL to the microservice which manages permissions @@ -31,12 +32,15 @@ type permissionMicroServiceCache struct { LastCheck time.Time session string permissions map[Permission]boolMicroServiceCache + sync.Mutex } // Function to check, if a user has a permission func (c *permissionMicroServiceCache) HasPermission(p Permission) (bool, error) { c.LastCheck = time.Now() + c.Lock() + defer c.Unlock() if cache, ok := c.permissions[p]; ok { before := time.Now().Add(-CacheConfig.After.Duration) if before.After(cache.LastCheck) { @@ -63,7 +67,7 @@ func (c *permissionMicroServiceCache) HasPermission(p Permission) (bool, error) // Cache for permissions var permissionCache map[string]*permissionMicroServiceCache - +var permissionMutex sync.Mutex // Function to initialize the permission cache func init() { permissionCache = make(map[string]*permissionMicroServiceCache) @@ -71,6 +75,8 @@ func init() { // Function to check, if the current session has any permissions func HasPermission(session string, p int) (bool, error) { + permissionMutex.Lock() + defer permissionMutex.Unlock() _, ok := permissionCache[session] if !ok { permissionCache[session] = &permissionMicroServiceCache{ diff --git a/runtime/productcache.go b/runtime/productcache.go index d267176..716969e 100644 --- a/runtime/productcache.go +++ b/runtime/productcache.go @@ -7,6 +7,7 @@ import ( "time" "github.com/genofire/hs_master-kss-monolith/lib/log" + "sync" ) // URL to the microservice which manages the products (product catalogue) @@ -20,6 +21,7 @@ type boolMicroServiceCache struct { // Cache for existing products var productExistCache map[int64]boolMicroServiceCache +var productMutex sync.Mutex // Function to initialize the cache for existing products func init() { @@ -28,6 +30,8 @@ func init() { // Function to check on the other microservice (product catalogue) if the product exists func ProductExists(id int64) (bool, error) { + productMutex.Lock() + defer productMutex.Unlock() if cache, ok := productExistCache[id]; ok { return cache.Value, nil } diff --git a/webroot/static/html/item.html b/webroot/static/html/item.html index 78e4325..a3003ee 100644 --- a/webroot/static/html/item.html +++ b/webroot/static/html/item.html @@ -31,9 +31,8 @@ {{item.position}} {{item.comment}} - + - {{item.fouled_at|date:"shortDate"}}