1
0
forked from MTSR/mapserver

sqlite perf/safety tradeoff

This commit is contained in:
NatureFreshMilk 2019-01-29 18:00:00 +01:00
parent f0d6d7c19b
commit 4f53a7996e
4 changed files with 30 additions and 3 deletions

View File

@ -53,8 +53,12 @@ type SearchQuery struct {
}
type DBAccessor interface {
//migrates the database
Migrate() error
//true = speed,unsafe / false = safe
EnableSpeedSafetyTradeoff(enableSpeed bool) error
//Generic map objects (poi, etc)
GetMapData(q SearchQuery) ([]*MapObject, error)
RemoveMapData(pos *coords.MapBlockCoords) error

View File

@ -9,8 +9,6 @@ import (
const migrateScript = `
PRAGMA foreign_keys = ON;
-- PRAGMA journal_mode = MEMORY;
-- PRAGMA synchronous = OFF;
create table if not exists objects(
id integer primary key autoincrement,
@ -64,3 +62,15 @@ func (db *Sqlite3Accessor) Migrate() error {
return nil
}
func (db *Sqlite3Accessor) EnableSpeedSafetyTradeoff(enableSpeed bool) error {
if enableSpeed {
_, err := db.db.Exec("PRAGMA journal_mode = MEMORY; PRAGMA synchronous = OFF;")
return err
} else {
_, err := db.db.Exec("PRAGMA journal_mode = TRUNCATE; PRAGMA synchronous = ON;")
return err
}
}

View File

@ -7,7 +7,7 @@ import (
func NewSqliteAccessor(filename string) (*Sqlite3Accessor, error) {
//TODO: flag/config for unsafe db access
db, err := sql.Open("sqlite3", filename+"?_timeout=500&_journal_mode=MEMORY&_synchronous=OFF")
db, err := sql.Open("sqlite3", filename+"?_timeout=500")
db.SetMaxOpenConns(1)
if err != nil {

View File

@ -15,7 +15,20 @@ func Job(ctx *app.App) {
}
if rstate.InitialRun {
//fast, unsafe mode
err := ctx.Objectdb.EnableSpeedSafetyTradeoff(true)
if err != nil {
panic(err)
}
initialRender(ctx, jobs)
//normal, safe mode
err = ctx.Objectdb.EnableSpeedSafetyTradeoff(false)
if err != nil {
panic(err)
}
}
incrementalRender(ctx, jobs)