Documentation
¶
Overview ¶
Package staleness holds the effective doc_type policy store. Read-time needs-verification is content/event-driven (the section flag), not age-based; this package no longer computes freshness from a clock.
Index ¶
- type PolicyStore
- func (s *PolicyStore) All() map[string]models.EffectivePolicy
- 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 ¶
This section is empty.
Types ¶
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) 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.