diff options
author | 2023-07-25 09:34:05 +0100 | |
---|---|---|
committer | 2023-07-25 10:34:05 +0200 | |
commit | 5f3e0957179eddd088e82b8f8f493164cbc9ce37 (patch) | |
tree | b169630ef1ac269dc96d74b533f6663dc0f1e6fc /internal/db/bundb/relationship_block.go | |
parent | [feature/performance] support uncaching remote emoji + scheduled cleanup func... (diff) | |
download | gotosocial-5f3e0957179eddd088e82b8f8f493164cbc9ce37.tar.xz |
[performance] retry db queries on busy errors (#2025)
* catch SQLITE_BUSY errors, wrap bun.DB to use our own busy retrier, remove unnecessary db.Error type
Signed-off-by: kim <grufwub@gmail.com>
* remove dead code
Signed-off-by: kim <grufwub@gmail.com>
* remove more dead code, add missing error arguments
Signed-off-by: kim <grufwub@gmail.com>
* update sqlite to use maxOpenConns()
Signed-off-by: kim <grufwub@gmail.com>
* add uncommitted changes
Signed-off-by: kim <grufwub@gmail.com>
* use direct calls-through for the ConnIface to make sure we don't double query hook
Signed-off-by: kim <grufwub@gmail.com>
* expose underlying bun.DB better
Signed-off-by: kim <grufwub@gmail.com>
* retry on the correct busy error
Signed-off-by: kim <grufwub@gmail.com>
* use longer possible maxRetries for db retry-backoff
Signed-off-by: kim <grufwub@gmail.com>
* remove the note regarding max-open-conns only applying to postgres
Signed-off-by: kim <grufwub@gmail.com>
* improved code commenting
Signed-off-by: kim <grufwub@gmail.com>
* remove unnecessary infof call (just use info)
Signed-off-by: kim <grufwub@gmail.com>
* rename DBConn to WrappedDB to better follow sql package name conventions
Signed-off-by: kim <grufwub@gmail.com>
* update test error string checks
Signed-off-by: kim <grufwub@gmail.com>
* shush linter
Signed-off-by: kim <grufwub@gmail.com>
* update backoff logic to be more transparent
Signed-off-by: kim <grufwub@gmail.com>
---------
Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/db/bundb/relationship_block.go')
-rw-r--r-- | internal/db/bundb/relationship_block.go | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/internal/db/bundb/relationship_block.go b/internal/db/bundb/relationship_block.go index fa68a2e97..948e82fcb 100644 --- a/internal/db/bundb/relationship_block.go +++ b/internal/db/bundb/relationship_block.go @@ -28,7 +28,7 @@ import ( "github.com/uptrace/bun" ) -func (r *relationshipDB) IsBlocked(ctx context.Context, sourceAccountID string, targetAccountID string) (bool, db.Error) { +func (r *relationshipDB) IsBlocked(ctx context.Context, sourceAccountID string, targetAccountID string) (bool, error) { block, err := r.GetBlock( gtscontext.SetBarebones(ctx), sourceAccountID, @@ -61,7 +61,7 @@ func (r *relationshipDB) GetBlockByID(ctx context.Context, id string) (*gtsmodel ctx, "ID", func(block *gtsmodel.Block) error { - return r.conn.NewSelect().Model(block). + return r.db.NewSelect().Model(block). Where("? = ?", bun.Ident("block.id"), id). Scan(ctx) }, @@ -74,7 +74,7 @@ func (r *relationshipDB) GetBlockByURI(ctx context.Context, uri string) (*gtsmod ctx, "URI", func(block *gtsmodel.Block) error { - return r.conn.NewSelect().Model(block). + return r.db.NewSelect().Model(block). Where("? = ?", bun.Ident("block.uri"), uri). Scan(ctx) }, @@ -87,7 +87,7 @@ func (r *relationshipDB) GetBlock(ctx context.Context, sourceAccountID string, t ctx, "AccountID.TargetAccountID", func(block *gtsmodel.Block) error { - return r.conn.NewSelect().Model(block). + return r.db.NewSelect().Model(block). Where("? = ?", bun.Ident("block.account_id"), sourceAccountID). Where("? = ?", bun.Ident("block.target_account_id"), targetAccountID). Scan(ctx) @@ -104,7 +104,7 @@ func (r *relationshipDB) getBlock(ctx context.Context, lookup string, dbQuery fu // Not cached! Perform database query if err := dbQuery(&block); err != nil { - return nil, r.conn.ProcessError(err) + return nil, r.db.ProcessError(err) } return &block, nil @@ -142,8 +142,8 @@ func (r *relationshipDB) getBlock(ctx context.Context, lookup string, dbQuery fu func (r *relationshipDB) PutBlock(ctx context.Context, block *gtsmodel.Block) error { return r.state.Caches.GTS.Block().Store(block, func() error { - _, err := r.conn.NewInsert().Model(block).Exec(ctx) - return r.conn.ProcessError(err) + _, err := r.db.NewInsert().Model(block).Exec(ctx) + return r.db.ProcessError(err) }) } @@ -163,11 +163,11 @@ func (r *relationshipDB) DeleteBlockByID(ctx context.Context, id string) error { } // Finally delete block from DB. - _, err = r.conn.NewDelete(). + _, err = r.db.NewDelete(). Table("blocks"). Where("? = ?", bun.Ident("id"), id). Exec(ctx) - return r.conn.ProcessError(err) + return r.db.ProcessError(err) } func (r *relationshipDB) DeleteBlockByURI(ctx context.Context, uri string) error { @@ -186,18 +186,18 @@ func (r *relationshipDB) DeleteBlockByURI(ctx context.Context, uri string) error } // Finally delete block from DB. - _, err = r.conn.NewDelete(). + _, err = r.db.NewDelete(). Table("blocks"). Where("? = ?", bun.Ident("uri"), uri). Exec(ctx) - return r.conn.ProcessError(err) + return r.db.ProcessError(err) } func (r *relationshipDB) DeleteAccountBlocks(ctx context.Context, accountID string) error { var blockIDs []string // Get full list of IDs. - if err := r.conn.NewSelect(). + if err := r.db.NewSelect(). Column("id"). Table("blocks"). WhereOr("? = ? OR ? = ?", @@ -207,7 +207,7 @@ func (r *relationshipDB) DeleteAccountBlocks(ctx context.Context, accountID stri accountID, ). Scan(ctx, &blockIDs); err != nil { - return r.conn.ProcessError(err) + return r.db.ProcessError(err) } defer func() { @@ -228,9 +228,9 @@ func (r *relationshipDB) DeleteAccountBlocks(ctx context.Context, accountID stri } // Finally delete all from DB. - _, err := r.conn.NewDelete(). + _, err := r.db.NewDelete(). Table("blocks"). Where("? IN (?)", bun.Ident("id"), bun.In(blockIDs)). Exec(ctx) - return r.conn.ProcessError(err) + return r.db.ProcessError(err) } |