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 ¶
- func Preview(content string, max int) string
- type CheckResult
- type PolicyStore
- func (s *PolicyStore) All() map[string]models.EffectivePolicy
- func (s *PolicyStore) DaysByDocType() map[string]int
- func (s *PolicyStore) DocTypesWhere(pred func(models.EffectivePolicy) bool) []string
- func (s *PolicyStore) EffectiveFor(docType string) models.EffectivePolicy
- func (s *PolicyStore) Load(ctx context.Context) error
- func (s *PolicyStore) Recompute(ctx context.Context) error
- func (s *PolicyStore) Rows(ctx context.Context) ([]models.DocTypePolicy, error)
- func (s *PolicyStore) Upsert(ctx context.Context, row models.DocTypePolicy) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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
func (s *PolicyStore) All() map[string]models.EffectivePolicy
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
func (s *PolicyStore) Rows(ctx context.Context) ([]models.DocTypePolicy, error)
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.