mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
Fix: Performance issues and sqlite locking (#74)
* fix: performance issues and sqlite locking * fix: dashboard release stats was reversed * refactor: open and migrate db * chore: cleanup
This commit is contained in:
parent
d8c37dde2f
commit
f466657ed4
25 changed files with 362 additions and 658 deletions
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
@ -10,7 +9,6 @@ import (
|
|||
"github.com/r3labs/sse/v2"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/pflag"
|
||||
_ "modernc.org/sqlite"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/action"
|
||||
"github.com/autobrr/autobrr/internal/auth"
|
||||
|
@ -60,19 +58,11 @@ func main() {
|
|||
log.Info().Msgf("Version: %v", version)
|
||||
log.Info().Msgf("Log-level: %v", cfg.LogLevel)
|
||||
|
||||
// if configPath is set then put database inside that path, otherwise create wherever it's run
|
||||
var dataSource = database.DataSourceName(configPath, "autobrr.db")
|
||||
|
||||
// open database connection
|
||||
db, err := sql.Open("sqlite", dataSource)
|
||||
if err != nil {
|
||||
db := database.NewSqliteDB(configPath)
|
||||
if err := db.Open(); err != nil {
|
||||
log.Fatal().Err(err).Msg("could not open db connection")
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
if err = database.Migrate(db); err != nil {
|
||||
log.Fatal().Err(err).Msg("could not migrate db")
|
||||
}
|
||||
|
||||
// setup repos
|
||||
var (
|
||||
|
@ -125,12 +115,15 @@ func main() {
|
|||
case syscall.SIGHUP:
|
||||
log.Print("shutting down server sighup")
|
||||
srv.Shutdown()
|
||||
db.Close()
|
||||
os.Exit(1)
|
||||
case syscall.SIGINT, syscall.SIGQUIT:
|
||||
srv.Shutdown()
|
||||
db.Close()
|
||||
os.Exit(1)
|
||||
case syscall.SIGKILL, syscall.SIGTERM:
|
||||
srv.Shutdown()
|
||||
db.Close()
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue