|
@@ -41,7 +41,7 @@ func NewDashboardFilereader(cfg *DashboardsAsConfig, log log.Logger) (*fileReade
|
|
|
Path: path,
|
|
Path: path,
|
|
|
log: log,
|
|
log: log,
|
|
|
dashboardRepo: dashboards.GetRepository(),
|
|
dashboardRepo: dashboards.GetRepository(),
|
|
|
- cache: gocache.New(5*time.Minute, 10*time.Minute),
|
|
|
|
|
|
|
+ cache: gocache.New(5*time.Minute, 30*time.Minute),
|
|
|
}, nil
|
|
}, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -87,23 +87,23 @@ func (fr *fileReader) walkFolder() error {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return filepath.Walk(fr.Path, func(path string, f os.FileInfo, err error) error {
|
|
|
|
|
|
|
+ return filepath.Walk(fr.Path, func(path string, fileInfo os.FileInfo, err error) error {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
- if f.IsDir() {
|
|
|
|
|
- if strings.HasPrefix(f.Name(), ".") {
|
|
|
|
|
|
|
+ if fileInfo.IsDir() {
|
|
|
|
|
+ if strings.HasPrefix(fileInfo.Name(), ".") {
|
|
|
return filepath.SkipDir
|
|
return filepath.SkipDir
|
|
|
}
|
|
}
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if !strings.HasSuffix(f.Name(), ".json") {
|
|
|
|
|
|
|
+ if !strings.HasSuffix(fileInfo.Name(), ".json") {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
cachedDashboard, exist := fr.getCache(path)
|
|
cachedDashboard, exist := fr.getCache(path)
|
|
|
- if exist && cachedDashboard.UpdatedAt == f.ModTime() {
|
|
|
|
|
|
|
+ if exist && cachedDashboard.UpdatedAt == fileInfo.ModTime() {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -116,6 +116,7 @@ func (fr *fileReader) walkFolder() error {
|
|
|
cmd := &models.GetDashboardQuery{Slug: dash.Dashboard.Slug}
|
|
cmd := &models.GetDashboardQuery{Slug: dash.Dashboard.Slug}
|
|
|
err = bus.Dispatch(cmd)
|
|
err = bus.Dispatch(cmd)
|
|
|
|
|
|
|
|
|
|
+ // if we dont have the dashboard in the db, save it!
|
|
|
if err == models.ErrDashboardNotFound {
|
|
if err == models.ErrDashboardNotFound {
|
|
|
fr.log.Debug("saving new dashboard", "file", path)
|
|
fr.log.Debug("saving new dashboard", "file", path)
|
|
|
_, err = fr.dashboardRepo.SaveDashboard(dash)
|
|
_, err = fr.dashboardRepo.SaveDashboard(dash)
|
|
@@ -127,11 +128,12 @@ func (fr *fileReader) walkFolder() error {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if cmd.Result.Updated.Unix() >= f.ModTime().Unix() {
|
|
|
|
|
|
|
+ // break if db version is newer then fil version
|
|
|
|
|
+ if cmd.Result.Updated.Unix() >= fileInfo.ModTime().Unix() {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fr.log.Debug("no dashboard in cache. loading dashboard from disk into database.", "file", path)
|
|
|
|
|
|
|
+ fr.log.Debug("loading dashboard from disk into database.", "file", path)
|
|
|
_, err = fr.dashboardRepo.SaveDashboard(dash)
|
|
_, err = fr.dashboardRepo.SaveDashboard(dash)
|
|
|
return err
|
|
return err
|
|
|
})
|
|
})
|