mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-24 03:03:33 -06:00
[feature/performance] sqlite pragma optimize on close (#2596)
* wrap database drivers in order to handle error processing, hooks, etc * remove dead code * add code comment, remove unused blank imports
This commit is contained in:
parent
b6fe8e7a5b
commit
6738fd5bb0
31 changed files with 372 additions and 660 deletions
|
|
@ -18,6 +18,8 @@
|
|||
package bundb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
|
|
@ -113,6 +115,25 @@ func whereStartsLike(
|
|||
)
|
||||
}
|
||||
|
||||
// exists checks the results of a SelectQuery for the existence of the data in question, masking ErrNoEntries errors.
|
||||
func exists(ctx context.Context, query *bun.SelectQuery) (bool, error) {
|
||||
exists, err := query.Exists(ctx)
|
||||
switch err {
|
||||
case nil:
|
||||
return exists, nil
|
||||
case sql.ErrNoRows:
|
||||
return false, nil
|
||||
default:
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
// notExists checks the results of a SelectQuery for the non-existence of the data in question, masking ErrNoEntries errors.
|
||||
func notExists(ctx context.Context, query *bun.SelectQuery) (bool, error) {
|
||||
exists, err := exists(ctx, query)
|
||||
return !exists, err
|
||||
}
|
||||
|
||||
// loadPagedIDs loads a page of IDs from given SliceCache by `key`, resorting to `loadDESC` if required. Uses `page` to sort + page resulting IDs.
|
||||
// NOTE: IDs returned from `cache` / `loadDESC` MUST be in descending order, otherwise paging will not work correctly / return things out of order.
|
||||
func loadPagedIDs(cache *cache.SliceCache[string], key string, page *paging.Page, loadDESC func() ([]string, error)) ([]string, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue