tgstore

package
v0.0.0-...-1a3a2fa Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const StoreCtxKey storeCtxKey = "store"

Variables

View Source
var (
	ErrNotFound              = errors.New("talkgroup not found")
	ErrNoSuchSystem          = errors.New("no such system")
	ErrInvalidOrderBy        = errors.New("invalid pagination orderBy value")
	ErrReference             = errors.New("item is still referenced, cannot delete")
	ErrSystemAndTGsSpecified = errors.New("system filter and individual talkgroups specified")
)

Functions

func CtxWithStore

func CtxWithStore(ctx context.Context, s Store) context.Context

func NewCache

func NewCache(db database.Store, met metrics.Metrics) *cache

NewCache returns a new cache Store.

func TGsToDBTGs

func TGsToDBTGs(tgs tgsp.IDs) []database.TGID

Types

type Filter

type Filter interface {
	Recompile(ctx context.Context) error
	TagRefs() []string
}

Filter is satisfied by filters.

type FilterCache

type FilterCache interface {
	// RegisterFilter registers a filter with the cache so it may be updated if referenced tags change.
	RegisterFilter(Filter)

	// UnregisterFilter unregisters a filter.
	UnregisterFilter(Filter)
}

FilterCache allows tgstore to track tag changes to keep filters updated.

type Option

type Option func(*options)

func WithFilter

func WithFilter(f *string) Option

func WithPagination

func WithPagination(p *Pagination, defPerPage int, totalDest *int) Option

type Pagination

type Pagination struct {
	common.Pagination

	OrderBy   *TGOrder              `json:"orderBy"`
	Direction *common.SortDirection `json:"dir"`
}

func (*Pagination) SortDir

func (p *Pagination) SortDir() (string, error)

SortDir computes the sortField_order string used by the GetTalkgroupsP SQL query.

type Store

type Store interface {
	// UpdateTG updates a talkgroup record.
	UpdateTG(ctx context.Context, input database.UpdateTalkgroupParams) (*tgsp.Talkgroup, error)

	// UpsertTGs upserts a slice of talkgroups.
	UpsertTGs(ctx context.Context, system int, input []database.UpsertTalkgroupParams) ([]*tgsp.Talkgroup, error)

	// CreateSystem creates a new system with the specified name and ID.
	CreateSystem(ctx context.Context, id int, name string, learned bool) error

	// TG retrieves a Talkgroup from the Store.
	TG(ctx context.Context, tg tgsp.ID) (*tgsp.Talkgroup, error)

	// TGs retrieves many talkgroups from the Store.
	TGs(ctx context.Context, tgs tgsp.IDs, opts ...Option) ([]*tgsp.Talkgroup, error)

	// TGsByTags gets talkgroups by tags any, all, and not.
	TGsByTags(ctx context.Context, tagsAll, tagsAny, tagsNot []string) (tgsp.IDs, error)

	// LearnSystem learns the system from a call.
	LearnSystem(ctx context.Context, call *calls.Call) error

	// LearnTG learns the talkgroup from a Call.
	LearnTG(ctx context.Context, call *calls.Call) (*tgsp.Talkgroup, error)

	// SystemTGs retrieves all Talkgroups associated with a System.
	SystemTGs(ctx context.Context, systemID int, opts ...Option) ([]*tgsp.Talkgroup, error)

	// DeleteTG deletes a talkgroup record.
	DeleteTG(ctx context.Context, id tgsp.ID) error

	// DeleteSystem deletes a system. The system must have no talkgroups or incidents.
	DeleteSystem(ctx context.Context, id int) error

	// SystemName retrieves a system name from the store. It returns the record and whether one was found.
	SystemName(ctx context.Context, id int) (string, bool)

	// Tags returns all distinct tags.
	Tags(ctx context.Context) ([]string, error)

	// Hint hints the Store that the provided talkgroups will be asked for.
	Hint(ctx context.Context, tgs []tgsp.ID) error

	// Load loads the provided talkgroup ID tuples into the Store.
	Load(ctx context.Context, tgs database.TGTuplesU) error

	// Invalidate invalidates any caching in the Store.
	Invalidate()

	// Weight returns the final weight of this talkgroup, including its static and rules-derived weight.
	Weight(ctx context.Context, id tgsp.ID, t time.Time) float64

	FilterCache

	Metrics() *TGStoreMetrics

	// Hupper
	HUP(*config.Config)
}

func FromCtx

func FromCtx(ctx context.Context) Store

type TGOrder

type TGOrder string
const (
	TGOrderID    TGOrder = "id"
	TGOrderTGID  TGOrder = "tgid"
	TGOrderGroup TGOrder = "group"
	TGOrderName  TGOrder = "name"
	TGOrderAlpha TGOrder = "alpha"
)

func (*TGOrder) IsValid

func (t *TGOrder) IsValid() bool

type TGStoreMetrics

type TGStoreMetrics struct {
	CacheHitCount  prometheus.Counter `help:"Talkgroup cache hits"`
	CacheMissCount prometheus.Counter `help:"Talkgroup cache misses"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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