forked from MTSR/mapserver
sqlite perf/safety tradeoff
This commit is contained in:
parent
f0d6d7c19b
commit
4f53a7996e
@ -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
|
||||
|
@ -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
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user