fix: drop sqlite shared cache (#10812)

Use of sqlite shared cache is discouraged and obsolete. wal mode should be used instead.

- https://sqlite.org/sharedcache.html#use_of_shared_cache_is_discouraged

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10812
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-committed-by: Michael Kriese <michael.kriese@visualon.de>
This commit is contained in:
Michael Kriese 2026-01-13 21:04:35 +01:00 committed by Gusted
parent 5afa5a2b5a
commit 1dceb23868
2 changed files with 12 additions and 5 deletions

View file

@ -239,12 +239,19 @@ func dbConnStrWithHost(host string) (string, error) {
if err := os.MkdirAll(filepath.Dir(Database.Path), os.ModePerm); err != nil {
return "", fmt.Errorf("failed to create directories: %w", err)
}
journalMode := ""
opts := ""
if Database.SQLiteJournalMode != "" {
journalMode = "&_journal_mode=" + Database.SQLiteJournalMode
opts = "&_journal_mode=" + Database.SQLiteJournalMode
}
connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate%s",
Database.Path, Database.Timeout, journalMode)
// in memory mode needs shared cache to be usable by multiple connections
// only used in tests normally
if Database.Path == ":memory:" {
opts += "&cache=shared"
} else {
opts += "&mode=rwc"
}
connStr = fmt.Sprintf("file:%s?_busy_timeout=%d&_txlock=immediate%s", Database.Path, Database.Timeout, opts)
default:
return "", fmt.Errorf("unknown database type: %s", Database.Type)
}