View Source Indexed.Actions.Warm (Indexed v0.0.1)
Holds internal state info during operations.
Link to this section Summary
Types
Data option for warming the cache. If data_tuple, the given ordering is explicit and we can assume it's correct and skip a sorting routine.
A list of records, wrapped in a hint about a field and direction it's already sorted by.
:data_tuple
- full input data set with order/direction hint:entity_name
- entity name atom (eg.:cars
):id_key
- Specifies how to find the id for a record. SeeIndexed.Entity.t/0
.:index_ref
- ETS table reference for storing index data
Functions
Return a list of all ids from the collection
.
From a field, make a compare function, suitable for Enum.sort/2
.
Normalize warm/1
's data option.
Normalize fields.
Normalize the prefilters option to tuples, adding nil
prefilter if needed.
For a set of entities, load data and indexes to ETS for each.
Create the asc and desc indexes for one field.
Link to this section Types
@type data_opt() :: data_tuple() | Indexed.record() | [Indexed.record()] | nil
Data option for warming the cache. If data_tuple, the given ordering is explicit and we can assume it's correct and skip a sorting routine.
@type data_tuple() :: {sort_dir :: :asc | :desc, sort_field :: atom(), [Indexed.record()]}
A list of records, wrapped in a hint about a field and direction it's already sorted by.
@type t() :: %Indexed.Actions.Warm{ data_tuple: data_tuple(), entity_name: atom(), id_key: any(), index_ref: :ets.tid() }
:data_tuple
- full input data set with order/direction hint:entity_name
- entity name atom (eg.:cars
):id_key
- Specifies how to find the id for a record. SeeIndexed.Entity.t/0
.:index_ref
- ETS table reference for storing index data
Link to this section Functions
@spec id_list([Indexed.record()], any()) :: [Indexed.id()]
Return a list of all ids from the collection
.
@spec record_sort_fn(Indexed.Entity.field()) :: (any(), any() -> boolean())
From a field, make a compare function, suitable for Enum.sort/2
.
@spec resolve_data_opt(data_opt(), atom(), [Indexed.Entity.field()]) :: {atom(), atom(), [Indexed.record()]}
Normalize warm/1
's data option.
@spec resolve_fields_opt([atom() | Indexed.Entity.field()], atom()) :: [ Indexed.Entity.field() ]
Normalize fields.
Normalize the prefilters option to tuples, adding nil
prefilter if needed.
For a set of entities, load data and indexes to ETS for each.
Argument is a keyword list where entity name atoms are keys and keyword lists of options are values. Allowed options are as follows:
:data
- List of maps (with id key) -- the data to index and cache. Required. May take one of the following forms:{direction, field, list}
- datalist
, with a hint that it is already sorted by field (atom) and direction (:asc or :desc),data_tuple/0
.list
- data list with unknown ordering; must be sorted for every field.
:fields
- List of field name atoms to index by. At least one required.- If field is a DateTime, use sort:
{:my_field, sort: :date_time}
. - Ascending and descending will be indexed for each field.
- If field is a DateTime, use sort:
:id_key
- Primary key to use in indexes and for accessing the records of this entity. SeeIndexed.Entity.t/0
. Default::id
.:prefilters
- List of field name atoms which should be prefiltered on. This means that separate indexes will be managed for each unique value for each of these fields, across all records of this entity type. While field namenil
refers to the indexes where no prefilter is used (all records) and it is included by default, it may be defined in the arguments if further options are needed. Default[{nil, []}]
. If options are needed, 2-element tuples may be used in place of the atom where the the first element is the field name atom, and the second is a keyword list of any of the following options::maintain_unique
- List of field name atoms for which a list of unique values under the prefilter will be managed. If thenil
prefilter is defined, leave the other prefilter fields off the:maintain_unique
option as these are automatically included. These lists can be fetched viaget_uniques_list/4
.
@spec warm_index(t(), Indexed.prefilter(), Indexed.Entity.field(), data_tuple()) :: true
Create the asc and desc indexes for one field.