staleness

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0 modules, 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 staleness decides a section's read-time freshness from age alone: two per-doc_type clocks (a verification-age nudge and an expiration-age withhold) under the tenant staleness mode. No content inspection — withholding is age-based.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Preview

func Preview(content string, max int) string

Preview returns a short leading-text prefix of content (default 200 chars), used as the headingless fallback for a withheld section.

Types

type CheckResult

type CheckResult struct {
	Stale            bool
	Expired          bool
	Age              time.Duration
	VerificationDays int
	ExpirationDays   int
}

CheckResult describes a section's freshness against its two doc_type clocks. Stale = past the verification age (nudge). Expired = past the expiration age under hard mode (withhold). Age is measured from verified_at, else created_at.

func Check

func Check(store *PolicyStore, section models.Section, docType, mode string) CheckResult

Check evaluates a section under mode. verification_age 0 disables the nudge; expiration_age 0 (and any non-hard mode) disables the withhold. NULL verified_at is treated as verified at creation (spec "Age is measured from last verification").

type PolicyStore added in v1.2.0

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

PolicyStore holds the effective doc_type policy set behind an atomic snapshot, loaded once at boot and recomputed on admin write (no TTL, no per-request DB hit). config-invalidation reloads it on other replicas via Recompute.

func NewPolicyStore added in v1.2.0

func NewPolicyStore(db *gorm.DB) *PolicyStore

NewPolicyStore returns a store seeded with the resolved default policies, so an un-Loaded store still serves the seeded rules; call Load at boot to pick up admin-edited rows.

func NewPolicyStoreFromEffective added in v1.2.0

func NewPolicyStoreFromEffective(eff map[string]models.EffectivePolicy) *PolicyStore

NewPolicyStoreFromEffective serves a pre-resolved policy set directly, skipping the DB load — for in-process callers and tests that resolve policies themselves.

func (*PolicyStore) All added in v1.2.0

All returns a copy of the effective set keyed by doc_type.

func (*PolicyStore) DaysByDocType added in v1.2.0

func (s *PolicyStore) DaysByDocType() map[string]int

DaysByDocType maps each known doc_type to its verification age, for the search re-rank's per-doc_type penalty (ranking rides the verification clock, not expiration).

func (*PolicyStore) DocTypesWhere added in v1.2.0

func (s *PolicyStore) DocTypesWhere(pred func(models.EffectivePolicy) bool) []string

DocTypesWhere returns the doc_types whose effective policy satisfies pred, as a sorted slice — the SQL-array inputs (default_search, cleanup_scan, lint) that replace the old compiled-in EpisodicDocTypes bindings.

func (*PolicyStore) EffectiveFor added in v1.2.0

func (s *PolicyStore) EffectiveFor(docType string) models.EffectivePolicy

EffectiveFor returns a doc_type's effective policy, falling back to the reference row for an unknown doc_type.

func (*PolicyStore) Load added in v1.2.0

func (s *PolicyStore) Load(ctx context.Context) error

Load reads every policy row, resolves NULL inheritance, validates the merged set, and swaps the snapshot. A validation failure returns an error (boot stops) and leaves the current snapshot untouched.

func (*PolicyStore) Recompute added in v1.2.0

func (s *PolicyStore) Recompute(ctx context.Context) error

Recompute reloads after an admin write; satisfies the config-invalidation ReloadFunc signature.

func (*PolicyStore) Rows added in v1.2.0

Rows returns the raw policy rows (for the admin read + merged validation).

func (*PolicyStore) Upsert added in v1.2.0

func (s *PolicyStore) Upsert(ctx context.Context, row models.DocTypePolicy) error

Upsert writes one policy row (insert or update by doc_type), firing the trigger.

Jump to

Keyboard shortcuts

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