Fixed database locking issue when importing

This commit is contained in:
Stash Dev 2019-02-10 12:47:34 -08:00
parent 47e788ad64
commit 57307bfd01
2 changed files with 8 additions and 7 deletions

View File

@ -9,6 +9,7 @@ import (
_ "github.com/mattn/go-sqlite3"
"github.com/stashapp/stash/logger"
"github.com/stashapp/stash/utils"
"os"
)
var DB *sqlx.DB
@ -19,7 +20,8 @@ func Initialize(databasePath string) {
// https://github.com/mattn/go-sqlite3
conn, err := sqlx.Open("sqlite3", "file:"+databasePath+"?_fk=true")
conn.SetMaxOpenConns(10)
conn.SetMaxOpenConns(25)
conn.SetMaxIdleConns(4)
if err != nil {
logger.Fatalf("db.Open(): %q\n", err)
}
@ -27,12 +29,9 @@ func Initialize(databasePath string) {
}
func Reset(databasePath string) {
_, _ = DB.Exec("PRAGMA writable_schema = 1;")
_, _ = DB.Exec("delete from sqlite_master where type in ('table', 'index', 'trigger');")
_, _ = DB.Exec("PRAGMA writable_schema = 0;")
_, _ = DB.Exec("VACUUM;")
_, _ = DB.Exec("PRAGMA INTEGRITY_CHECK;")
runMigrations(databasePath)
_ = DB.Close()
_ = os.Remove(databasePath)
Initialize(databasePath)
}
// Migrate the database

View File

@ -41,6 +41,7 @@ func (t *ExportTask) Start(wg *sync.WaitGroup) {
func (t *ExportTask) ExportScenes(ctx context.Context) {
tx := database.DB.MustBeginTx(ctx, nil)
defer tx.Commit()
qb := models.NewSceneQueryBuilder()
studioQB := models.NewStudioQueryBuilder()
galleryQB := models.NewGalleryQueryBuilder()
@ -321,6 +322,7 @@ func (t *ExportTask) ExportStudios(ctx context.Context) {
func (t *ExportTask) ExportScrapedItems(ctx context.Context) {
tx := database.DB.MustBeginTx(ctx, nil)
defer tx.Commit()
qb := models.NewScrapedItemQueryBuilder()
sqb := models.NewStudioQueryBuilder()
scrapedItems, err := qb.All()