2020-02-05 16:49:51 +01:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2020-09-24 17:52:53 +02:00
|
|
|
"github.com/pkg/errors"
|
2020-11-23 19:39:44 +01:00
|
|
|
"gorm.io/gorm"
|
2020-02-05 16:49:51 +01:00
|
|
|
)
|
|
|
|
|
2020-11-23 19:59:01 +01:00
|
|
|
type SiteInfo struct {
|
2020-11-28 21:29:31 +01:00
|
|
|
Model
|
2020-11-23 19:59:01 +01:00
|
|
|
InitialSetup bool
|
|
|
|
PeriodicScanInterval int
|
|
|
|
ConcurrentWorkers int
|
|
|
|
}
|
2020-09-20 22:19:25 +02:00
|
|
|
|
2020-09-24 17:52:53 +02:00
|
|
|
// GetSiteInfo gets the site info row from the database, and creates it if it does not exist
|
2020-11-23 19:39:44 +01:00
|
|
|
func GetSiteInfo(db *gorm.DB) (*SiteInfo, error) {
|
|
|
|
|
|
|
|
var siteInfo SiteInfo
|
2020-02-05 16:49:51 +01:00
|
|
|
|
2020-11-23 19:59:01 +01:00
|
|
|
err := db.FirstOrCreate(&siteInfo, SiteInfo{
|
2020-11-23 19:39:44 +01:00
|
|
|
InitialSetup: true,
|
|
|
|
PeriodicScanInterval: 0,
|
|
|
|
ConcurrentWorkers: 3,
|
2020-11-23 19:59:01 +01:00
|
|
|
}).Error
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "get site info from database")
|
2020-02-05 16:49:51 +01:00
|
|
|
}
|
|
|
|
|
2020-11-23 19:39:44 +01:00
|
|
|
return &siteInfo, nil
|
2020-02-05 16:49:51 +01:00
|
|
|
}
|