use journal mode WAL for expand db use
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
package cronjob
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/alireza0/s-ui/database"
|
||||||
|
"github.com/alireza0/s-ui/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WALCheckpointJob struct{}
|
||||||
|
|
||||||
|
func NewWALCheckpointJob() *WALCheckpointJob {
|
||||||
|
return &WALCheckpointJob{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *WALCheckpointJob) Run() {
|
||||||
|
db := database.GetDB()
|
||||||
|
_, err := db.Raw("PRAGMA wal_checkpoint(FULL)").Rows()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("Error checkpointing WAL: ", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,8 @@ func (c *CronJob) Start(loc *time.Location, trafficAge int) error {
|
|||||||
}
|
}
|
||||||
// Start core if it is not running
|
// Start core if it is not running
|
||||||
c.cron.AddJob("@every 5s", NewCheckCoreJob())
|
c.cron.AddJob("@every 5s", NewCheckCoreJob())
|
||||||
|
// database WAL checkpoint
|
||||||
|
c.cron.AddJob("@every 10m", NewWALCheckpointJob())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ func OpenDB(dbPath string) error {
|
|||||||
if strings.Contains(dbPath, "?") {
|
if strings.Contains(dbPath, "?") {
|
||||||
sep = "&"
|
sep = "&"
|
||||||
}
|
}
|
||||||
dsn := dbPath + sep + "_busy_timeout=10000"
|
dsn := dbPath + sep + "_busy_timeout=10000&_journal_mode=WAL"
|
||||||
db, err = gorm.Open(sqlite.Open(dsn), c)
|
db, err = gorm.Open(sqlite.Open(dsn), c)
|
||||||
|
|
||||||
if config.IsDebug() {
|
if config.IsDebug() {
|
||||||
|
|||||||
Reference in New Issue
Block a user