Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve SQLite performance #1024

Merged
merged 22 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5882935
refactor: Improve SQLite performance with connection pooling and retr…
fmartingr Dec 10, 2024
9a02441
feat: Add withTx and withTxRetry methods to SQLiteDatabase for handli…
fmartingr Dec 10, 2024
b52dd10
refactor: add Init command to all databases
fmartingr Dec 10, 2024
e4e059b
refactor: Improve transaction handling with retry and error management
fmartingr Dec 10, 2024
99ab3d0
refactor: Remove panic/recover pattern in transaction handling
fmartingr Dec 10, 2024
739f860
refactor: Replace `errors.WithStack` with `fmt.Errorf` in transaction…
fmartingr Dec 10, 2024
ac4c329
docs: Add docstrings to `withTx` and `withTxRetry` methods in SQLite …
fmartingr Dec 10, 2024
673778f
feat: use new withTxRetry in SaveBookmarks
fmartingr Dec 10, 2024
f89af36
feat: sqlite inmmediate transactions by default
fmartingr Dec 10, 2024
bc0eb96
refactor: Split SQLiteDatabase into separate writer and reader dbbase…
fmartingr Dec 10, 2024
59822bd
refactor: Update Init method to configure both reader and writer data…
fmartingr Dec 10, 2024
51138f7
feat: use writer/reader sqlite databases
fmartingr Dec 10, 2024
4829ef1
refactor: Replace all read calls to use the `reader` database instance
fmartingr Dec 10, 2024
c7f0fb6
refactor: Replace errors.WithStack with fmt.Errorf and add nil checks
fmartingr Dec 10, 2024
e17a930
refactor: Use withTxRetry for SetDatabaseSchemaVersion method
fmartingr Dec 10, 2024
cac7580
fix: Simplify error handling in GetBookmark and GetAccount methods
fmartingr Dec 10, 2024
3d89306
refactor: Remove duplicated non-nil error checks in sqlite.go
fmartingr Dec 10, 2024
555803e
tests: use testutil instead of a manual in memory sqlite db
fmartingr Dec 10, 2024
6cdcf3b
fix: openbsd sqlite connection
fmartingr Dec 10, 2024
f70aef2
Merge branch 'master' into feat/sqlite-performace
fmartingr Dec 10, 2024
8eda47a
Merge branch 'master' into feat/sqlite-performace
fmartingr Dec 11, 2024
2e674cc
Merge branch 'master' into feat/sqlite-performace
fmartingr Jan 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (c Config) SetDefaults(logger *logrus.Logger, portableMode bool) {

// Set default database url if not set
if c.Database.DBMS == "" && c.Database.URL == "" {
c.Database.URL = fmt.Sprintf("sqlite:///%s", filepath.Join(c.Storage.DataDir, "shiori.db"))
c.Database.URL = fmt.Sprintf("sqlite:///%s?_txlock=immediate", filepath.Join(c.Storage.DataDir, "shiori.db"))
}

c.Http.SetDefaults(logger)
Expand Down
3 changes: 3 additions & 0 deletions internal/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ type DB interface {
// DBx is the underlying sqlx.DB
DBx() *sqlx.DB

// Init initializes the database
Init(ctx context.Context) error

// Migrate runs migrations for this database
Migrate(ctx context.Context) error

Expand Down
5 changes: 5 additions & 0 deletions internal/database/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func (db *MySQLDatabase) DBx() *sqlx.DB {
return db.DB
}

// Init initializes the database
func (db *MySQLDatabase) Init(ctx context.Context) error {
return nil
}

// Migrate runs migrations for this database engine
func (db *MySQLDatabase) Migrate(ctx context.Context) error {
if err := runMigrations(ctx, db, mysqlMigrations); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions internal/database/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ func (db *PGDatabase) DBx() *sqlx.DB {
return db.DB
}

// Init initializes the database
func (db *PGDatabase) Init(ctx context.Context) error {
return nil
}

// Migrate runs migrations for this database engine
func (db *PGDatabase) Migrate(ctx context.Context) error {
if err := runMigrations(ctx, db, postgresMigrations); err != nil {
Expand Down
Loading
Loading