review

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
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.

View Source
const SettingsKey = "review_criteria"

Variables

AudioCandidates is the set of fields that can be required only when the book has at least one audio file.

UniversalCandidates is the set of fields that can be required for all books.

Functions

func IsComplete

func IsComplete(book *models.Book, file *models.File, criteria Criteria) bool

IsComplete returns true iff MissingFields returns an empty slice for a main file.

func MissingFields

func MissingFields(book *models.Book, file *models.File, criteria Criteria) []string

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

func RecomputeForBooks(ctx context.Context, db bun.IDB, bookIDs []int, criteria Criteria) error

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

func RecomputeForFile(ctx context.Context, db bun.IDB, fileID int, criteria Criteria) error

RecomputeForFile reloads the file (with relations needed by completeness), computes its `reviewed` value, and persists. Override-set rows short-circuit. Supplements get reviewed=NULL.

func Save

func Save(ctx context.Context, settings *appsettings.Service, c Criteria) error

Save persists the criteria.

func SetOverride

func SetOverride(ctx context.Context, db bun.IDB, fileID int, override *string, criteria Criteria) error

SetOverride writes an explicit override and the timestamp, then writes the effective `reviewed` value. Pass override=nil to clear (then completeness drives reviewed).

func Validate

func Validate(c Criteria) error

Validate returns an error if any field name in the criteria isn't a known candidate.

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.

type Criteria

type Criteria struct {
	BookFields  []string `json:"book_fields"`
	AudioFields []string `json:"audio_fields"`
}

func Default

func Default() Criteria

Default returns the seeded review criteria.

func Load

func Load(ctx context.Context, settings *appsettings.Service) (Criteria, error)

Load reads the criteria from app settings, falling back to Default if unset.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址