|
@@ -7,7 +7,6 @@ import (
|
|
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
|
- gocache "github.com/patrickmn/go-cache"
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type DashboardsAsConfig struct {
|
|
type DashboardsAsConfig struct {
|
|
@@ -19,32 +18,6 @@ type DashboardsAsConfig struct {
|
|
|
Options map[string]interface{} `json:"options" yaml:"options"`
|
|
Options map[string]interface{} `json:"options" yaml:"options"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-type DashboardCache struct {
|
|
|
|
|
- internalCache *gocache.Cache
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func NewDashboardCache() *DashboardCache {
|
|
|
|
|
- return &DashboardCache{internalCache: gocache.New(5*time.Minute, 30*time.Minute)}
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func (fr *DashboardCache) addDashboardCache(key string, json *dashboards.SaveDashboardItem) {
|
|
|
|
|
- fr.internalCache.Add(key, json, time.Minute*10)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func (fr *DashboardCache) getCache(key string) (*dashboards.SaveDashboardItem, bool) {
|
|
|
|
|
- obj, exist := fr.internalCache.Get(key)
|
|
|
|
|
- if !exist {
|
|
|
|
|
- return nil, exist
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- dash, ok := obj.(*dashboards.SaveDashboardItem)
|
|
|
|
|
- if !ok {
|
|
|
|
|
- return nil, ok
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return dash, ok
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
func createDashboardJson(data *simplejson.Json, lastModified time.Time, cfg *DashboardsAsConfig, folderId int64) (*dashboards.SaveDashboardItem, error) {
|
|
func createDashboardJson(data *simplejson.Json, lastModified time.Time, cfg *DashboardsAsConfig, folderId int64) (*dashboards.SaveDashboardItem, error) {
|
|
|
dash := &dashboards.SaveDashboardItem{}
|
|
dash := &dashboards.SaveDashboardItem{}
|
|
|
dash.Dashboard = models.NewDashboardFromJson(data)
|
|
dash.Dashboard = models.NewDashboardFromJson(data)
|