Documentation
¶
Index ¶
- Constants
- Variables
- func IsComplete(book *models.Book, file *models.File, criteria Criteria) bool
- func MissingFields(book *models.Book, file *models.File, criteria Criteria) []string
- func RecomputeForBooks(ctx context.Context, db bun.IDB, bookIDs []int, criteria Criteria) error
- func RecomputeForFile(ctx context.Context, db bun.IDB, fileID int, criteria Criteria) error
- func Save(ctx context.Context, settings *appsettings.Service, c Criteria) error
- func SetOverride(ctx context.Context, db bun.IDB, fileID int, override *string, ...) error
- func Validate(c Criteria) error
- type BookReviewRecomputer
- type Criteria
Constants ¶
const ( FieldAuthors = "authors" FieldDescription = "description" FieldCover = "cover" FieldGenres = "genres" FieldTags = "tags" FieldSeries = "series" FieldSubtitle = "subtitle" FieldPublisher = "publisher" FieldIdentifiers = "identifiers" FieldReleaseDate = "release_date" FieldLanguage = "language" FieldURL = "url" FieldNarrators = "narrators" FieldChapters = "chapters" FieldAbridged = "abridged" )
Field constants — every name must be in either UniversalCandidates or AudioCandidates.
const RecomputeBatchSize = 500
RecomputeBatchSize bounds how long a batch holds the database's only connection, so other requests get a turn between batches during a large recompute.
const SettingsKey = "review_criteria"
Variables ¶
var AudioCandidates = []string{FieldNarrators, FieldChapters, FieldAbridged}
AudioCandidates is the set of fields that can be required only when the book has at least one audio file.
var UniversalCandidates = []string{ FieldAuthors, FieldDescription, FieldCover, FieldGenres, FieldTags, FieldSeries, FieldSubtitle, FieldPublisher, FieldIdentifiers, FieldReleaseDate, FieldLanguage, FieldURL, }
UniversalCandidates is the set of fields that can be required for all books.
Functions ¶
func IsComplete ¶
IsComplete returns true iff MissingFields returns an empty slice for a main file.
func MissingFields ¶
MissingFields returns the list of required-field names that are not satisfied for a single main file. The book and file must have all relations loaded.
For supplements, returns nil.
The criteria's BookFields apply to every file; AudioFields apply when the file is m4b.
func RecomputeForBooks ¶ added in v0.7.0
RecomputeForBooks recomputes reviewed for every file of each book and writes only the values that changed. It works in batches, each in its own transaction so a concurrent edit can't land between a batch's read and write. Don't wrap a large call in a transaction: that holds the connection for the whole run. When a batch fails, its books are retried one at a time, so a bad row costs only its own book; the returned error counts them and names the first.
func RecomputeForFile ¶
RecomputeForFile reloads the file (with relations needed by completeness), computes its `reviewed` value, and persists. Override-set rows short-circuit. Supplements get reviewed=NULL.
Types ¶
type BookReviewRecomputer ¶ added in v0.1.0
type BookReviewRecomputer interface {
RecomputeReviewedForBooks(ctx context.Context, bookIDs []int)
}
BookReviewRecomputer refreshes files.reviewed for every file of each book, loading the review criteria once. *books.Service satisfies it. pkg/books imports the genres, tags, people, and publishers packages, so their handlers take this interface instead of *books.Service to avoid an import cycle.