fix

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: GPL-3.0 Imports: 21 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fix contains functions for repairing the database data.

Index

Constants

View Source
const Trainer = "gamehack"

Variables

View Source
var ErrInvalidMerge = errors.New("source and target releaser names must be non-empty and distinct")

ErrInvalidMerge is returned when merge source or destination releaser names are invalid.

View Source
var ErrRepair = errors.New("fix: invalid repair option")

Functions

func Clear added in v1.16.1

func Clear()

Clear clears the in-memory releaser suggestion cache so the next lookup refreshes from the database.

func Indexes added in v1.16.1

func Indexes(ctx context.Context, sl *slog.Logger, db *sql.DB) error

Indexes ensures all recommended PostgreSQL indexes exist on the files table, drops legacy MySQL-migrated indexes, rebuilds all indexes concurrently, and runs VACUUM ANALYZE.

Must be called on *sql.DB outside a transaction block (required for CONCURRENTLY).

func Magics added in v0.17.0

func Magics(exec boil.ContextExecutor) error

Magics will set invalid file_magic_type to NULL. Invalid file_magic_type values are those that start with "ERROR: " or contain a "/" such as a mime-type.

func MergeReleaser added in v1.16.0

func MergeReleaser(ctx context.Context, exec boil.ContextExecutor, from, to string) (int64, error)

MergeReleaser renames all references of releaser "from" to "to" across group_brand_for and group_brand_by, clearing group_brand_by if both columns become identical.

func Optimize added in v1.16.1

func Optimize(ctx context.Context, db *sql.DB) error

Optimize reclaims storage occupied by dead tuples in the database and also analyzes the most efficient execution plans for queries.

Optimize runs VACUUM ANALYZE which cannot be executed inside a transaction block and should be called after any repair transaction has been committed.

func RunIndexes added in v1.16.1

func RunIndexes(ctx context.Context, sl *slog.Logger, db *sql.DB, dryRun bool) error

RunIndexes inspects the current PostgreSQL indexes on files and either logs the planned operations (when dryRun is true) or executes them concurrently.

func SyncFilesIDSeq added in v1.0.6

func SyncFilesIDSeq(exec boil.ContextExecutor) error

SyncFilesIDSeq will synchronize the files ID sequence with the current maximum ID.

This will only work with the correct database account permissions.

Types

type DupEntry added in v1.15.4

type DupEntry struct {
	Name    string
	RawName string
	Display string
	URI     string
	Kind    string
	Count   int
	Files   []DupFile
}

DupEntry represents a single releaser candidate within a duplicate cluster.

type DupFile added in v1.16.0

type DupFile struct {
	ObfuscatedID string
	Filename     string
}

DupFile represents an individual artifact file belonging to a minor duplicate entry.

type DupGroup added in v1.15.4

type DupGroup struct {
	Key     string
	Kind    string
	Tier    int
	Reason  string
	Entries []DupEntry
}

DupGroup represents a cluster of two or more potentially duplicate releaser names.

type DupReport added in v1.15.4

type DupReport struct {
	TotalReleasers int
	TotalClusters  int
	Tier1          []DupGroup
	Tier2          []DupGroup
	Tier3          []DupGroup
}

DupReport summarizes all detected duplicate clusters across confidence tiers.

func AnalyzeDuplicates added in v1.15.4

func AnalyzeDuplicates(rows []ReleaserCount) *DupReport

AnalyzeDuplicates runs the 3-tier in-memory clustering pipeline on a slice of releaser counts.

func Duplicates added in v1.15.4

func Duplicates(ctx context.Context, exec boil.ContextExecutor) (*DupReport, error)

Duplicates queries all distinct public releasers and clusters potential duplicates.

type Fix added in v1.14.0

type Fix string

type IndexPlan added in v1.16.1

type IndexPlan struct {
	Existing   []string // recommended indexes already present and valid
	Invalid    []string // indexes on files marked indisvalid = false
	Create     []string // recommended indexes missing (excluding trgm)
	CreateTrgm bool     // true if idx_files_filename_trgm is missing
	NeedTrgm   bool     // true if the pg_trgm extension is not installed yet
	Drop       []string // obsolete indexes currently present on files
}

IndexPlan describes the current PostgreSQL index state on files and what Indexes will change.

func PlanIndexes added in v1.16.1

func PlanIndexes(ctx context.Context, db *sql.DB) (IndexPlan, error)

PlanIndexes inspects PostgreSQL's system catalogs (read-only) to determine which indexes need to be created, dropped, or repaired on the files table.

type List added in v1.14.0

type List map[string]Fix

func Replacements added in v1.14.0

func Replacements() List

Replacements returns a copy of the replacers List.

type NumFile added in v1.14.0

type NumFile struct {
	ID           int64  `boil:"id"     json:"id"`
	UUID         string `boil:"uuid"   json:"uuid"`
	Filename     string `boil:"suffix" json:"filename"`
	ObfuscatedID string `boil:"-"      json:"obfuscatedId"`
}

NumFile represents a file with a numeric suffix.

type NumFiles added in v1.14.0

type NumFiles struct {
	Count int64     `boil:"-" json:"count"`
	Files []NumFile `boil:"-" json:"files"`
}

NumFiles represents files that have numeric suffixes that need fixing.

func NumSuffix added in v1.14.0

func NumSuffix(ctx context.Context, exec boil.ContextExecutor) (*NumFiles, error)

NumSuffix retrieves files with numeric suffixes from the database.

type ReleaserCount added in v1.15.4

type ReleaserCount struct {
	Releaser string `boil:"releaser"`
	Count    int    `boil:"count_sum"`
}

ReleaserCount holds a raw releaser name and its file count from the database.

func SuggestReleasers added in v1.16.1

func SuggestReleasers(
	ctx context.Context, exec boil.ContextExecutor, magazine bool, limit int, lookups ...string,
) ([]ReleaserCount, error)

SuggestReleasers returns up to limit releaser suggestions matching lookups, ranked by raw prefix match, normalized duplicate-aware match, and 1-char typo match, ordered by file count within each tier.

func Suggests added in v1.16.1

func Suggests(entries []Suggestion, limit int, lookups ...string) []ReleaserCount

Suggests matches lookups against pre-normalized entries in 3 priority tiers:

  1. Raw prefix match (exact existing behavior)
  2. Normalized fingerprint match (handles stop words, punctuation, apostrophes, numerals)
  3. 1-character typo or adjacent letter transposition (for normalized inputs >= 6 chars)

type Repair

type Repair int

Repair a column or type of data within the database.

const (
	// None does nothing.
	None Repair = iota - 1
	// Artifacts repairs all the artifact data.
	Artifacts
	// Releaser focuses on the releaser data using the group_brand_by and group_brand_for columns.
	Releaser
)

func (Repair) Run

func (r Repair) Run(ctx context.Context, sl *slog.Logger, exec boil.ContextExecutor) error

Run the database repair based on the repair option.

Call Optimize after committing the transaction to run VACUUM ANALYZE.

func (Repair) String added in v0.8.0

func (r Repair) String() string

type Suggestion added in v1.16.1

type Suggestion struct {
	// contains filtered or unexported fields
}

Suggestion is a pre-normalized releaser cached in memory for fast auto-suggestions.

func Suggest added in v1.16.1

func Suggest(rows []ReleaserCount) []Suggestion

Suggest pre-normalizes releaser rows and sorts them by file count descending.

Jump to

Keyboard shortcuts

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