gallerylib

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package gallerylib provides the business logic for importing and managing gallery content in the database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Importer

type Importer struct {
	Conn *sql.Conn
	Q    importerQueries

	// OnFolderCreated is called after UpsertPathChain successfully creates
	// a new folder (i.e., the folder did not exist and UpsertFolderReturningFolder
	// completed without error). Rare double-count possible when two workers
	// both observe ErrNoRows before either inserts; self-corrects on restart.
	OnFolderCreated func()
	// contains filtered or unexported fields
}

Importer provides methods for adding gallery content to the database.

folderCache and tiledDirs are batch-scoped memoization state. They are intentionally unexported and lazily initialized so a zero-value Importer (or one constructed without them) remains safe. Construct one Importer per batch and reuse it across files so the caches persist across files in the same batch.

func (*Importer) CreateRootFolderEntry

func (imp *Importer) CreateRootFolderEntry(ctx context.Context, mtime int64) (int64, error)

CreateRootFolderEntry creates or retrieves the root folder record in the database. It is idempotent and safe for concurrent calls. mtime is the filesystem modification time of the root directory (unix seconds). It returns the ID of the root folder.

func (*Importer) IsDirTiled added in v0.3.0

func (imp *Importer) IsDirTiled(dir string) bool

IsDirTiled reports whether the directory's folder-tile chain was already updated in this batch. Used by files.WriteFileInTx to skip redundant tile view queries and chain updates for subsequent files in the same directory.

func (*Importer) MarkDirTiled added in v0.3.0

func (imp *Importer) MarkDirTiled(dir string)

MarkDirTiled records that the directory's folder-tile chain was successfully updated. Must be called only after UpdateFolderTileChain succeeds, so a dir is never marked tiled when its tile update failed (which would cause later files in that dir to skip a tile update they still need).

func (*Importer) UpdateFolderTileChain

func (imp *Importer) UpdateFolderTileChain(ctx context.Context, folderID, tileFileID int64) error

UpdateFolderTileChain updates the tile_id for a given folder and recursively ascends the folder hierarchy. It sets the `tile_id` for each parent folder to the provided `tileFileID` until it reaches a folder that already has a tile or it reaches the root of the gallery. The `tileFileID` parameter must be an ID from the `files` table.

func (*Importer) UpsertPathChain

func (imp *Importer) UpsertPathChain(ctx context.Context, path string, mtime, size int64, md5 string, phash, width, height int64, mimeType string) (gallerydb.File, error)

UpsertPathChain ensures that all intermediate folders and the file record exist. It returns the final file record.

Jump to

Keyboard shortcuts

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