Fix database locked errors (#3153)

* Make read-only operations use WithReadTxn
* Allow one database write thread
* Add unit test for concurrent transactions
* Perform some actions after commit to release txn
* Suppress some errors from cancelled context
This commit is contained in:
WithoutPants
2022-11-21 06:49:10 +11:00
committed by GitHub
parent 420c6fa9d7
commit f39fa416a9
54 changed files with 626 additions and 311 deletions

View File

@@ -131,7 +131,7 @@ func (c Client) FindStashBoxSceneByFingerprints(ctx context.Context, sceneID int
func (c Client) FindStashBoxScenesByFingerprints(ctx context.Context, ids []int) ([][]*scraper.ScrapedScene, error) {
var fingerprints [][]*graphql.FingerprintQueryInput
if err := txn.WithTxn(ctx, c.txnManager, func(ctx context.Context) error {
if err := txn.WithReadTxn(ctx, c.txnManager, func(ctx context.Context) error {
qb := c.repository.Scene
for _, sceneID := range ids {
@@ -245,7 +245,7 @@ func (c Client) SubmitStashBoxFingerprints(ctx context.Context, sceneIDs []strin
var fingerprints []graphql.FingerprintSubmission
if err := txn.WithTxn(ctx, c.txnManager, func(ctx context.Context) error {
if err := txn.WithReadTxn(ctx, c.txnManager, func(ctx context.Context) error {
qb := c.repository.Scene
for _, sceneID := range ids {
@@ -386,7 +386,7 @@ func (c Client) FindStashBoxPerformersByNames(ctx context.Context, performerIDs
var performers []*models.Performer
if err := txn.WithTxn(ctx, c.txnManager, func(ctx context.Context) error {
if err := txn.WithReadTxn(ctx, c.txnManager, func(ctx context.Context) error {
qb := c.repository.Performer
for _, performerID := range ids {
@@ -420,7 +420,7 @@ func (c Client) FindStashBoxPerformersByPerformerNames(ctx context.Context, perf
var performers []*models.Performer
if err := txn.WithTxn(ctx, c.txnManager, func(ctx context.Context) error {
if err := txn.WithReadTxn(ctx, c.txnManager, func(ctx context.Context) error {
qb := c.repository.Performer
for _, performerID := range ids {
@@ -705,7 +705,7 @@ func (c Client) sceneFragmentToScrapedScene(ctx context.Context, s *graphql.Scen
ss.Image = getFirstImage(ctx, c.getHTTPClient(), s.Images)
}
if err := txn.WithTxn(ctx, c.txnManager, func(ctx context.Context) error {
if err := txn.WithReadTxn(ctx, c.txnManager, func(ctx context.Context) error {
pqb := c.repository.Performer
tqb := c.repository.Tag