A registry for Tornex.SpecQuery backed by a tree held by a globally registered GenServer.
This module will store each Tornex.SpecQuery and map the query to its Tornex.Scheduler.Bucket
to allow for the combination of queries. This only applies to Tornex.SpecQuery that are not quarantined.
Summary
Functions
Returns a specification to start this module under a supervisor.
Determine if a list of Tornex.SpecQuery is "conflict free".
Get the number of unique paths in a list of queries.
Greedily build subsets of the queries where the subsets of queries' parameters do not conflict.
Insert a Tornex.SpecQuery into the query tree.
Merge any applicable Tornex.SpecQuery for this combintion of a resource and resource ID together.
Merge "similar" queries to the Tornex.SpecQuery provided to create one query containing as many
selections as possible. Quarantined queries will not be merged and will be executed as provided.
Traverse the state tree and remove the branches that are being fulfilled by the
Tornex.Scheduler.ExecutionUnit.
Start the Tornex.Scheduler.QueryRegistry GenServer.
Types
@type state() :: %{ required(String.t()) => %{ required(Tornex.SpecQuery.parameter() | nil) => %{ required(String.t()) => [Tornex.SpecQuery.t()] } } }
The state for the GenServer of the tree representing pending, un-fulfilled API calls.
Example Tree
user
├─ 2383326
│ ├─ profile
│ ├─ attacks
├─ 1
faction
├─ 15644
│ ├─ attacks
torn
├─ nil
│ ├─ crimes
│ ├─ items
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec conflict_free?(queries :: [Tornex.SpecQuery.t()]) :: boolean()
Determine if a list of Tornex.SpecQuery is "conflict free".
For the list of queries to be "conflict free", all of the queries must have one unique value for each parameter key-value pair.
@spec count_unique_paths(queries :: [Tornex.SpecQuery.t()]) :: non_neg_integer()
Get the number of unique paths in a list of queries.
@spec greedy_subsets(queries :: [Tornex.SpecQuery.t()]) :: [[Tornex.SpecQuery.t()]]
Greedily build subsets of the queries where the subsets of queries' parameters do not conflict.
@spec insert(query :: Tornex.SpecQuery.t()) :: :ok
Insert a Tornex.SpecQuery into the query tree.
The Tornex.SpecQuery must be registered against an origin (of type Genserver.from()) so that the
Tornex.Scheduler.ExecutionUnit generated including the Tornex.SpecQuery will be able to return the
portion of the response corresponding to the Tornex.SpecQuery to the origin.
@spec merge(query :: Tornex.SpecQuery.t()) :: Tornex.Scheduler.ExecutionUnit.t() | Tornex.SpecQuery.t()
Merge any applicable Tornex.SpecQuery for this combintion of a resource and resource ID together.
@spec merge_similar(query :: Tornex.SpecQuery.t(), state :: state()) :: Tornex.Scheduler.ExecutionUnit.t() | Tornex.SpecQuery.t()
Merge "similar" queries to the Tornex.SpecQuery provided to create one query containing as many
selections as possible. Quarantined queries will not be merged and will be executed as provided.
NOTE: The queries may not necessarily be merged into the query provided if it is more efficient to merge the queries into a different non-public query.
For a query to be similar to another query, the query must:
- Be for the same resource and resource ID.
- Not have conflicting parameters where the same key has different values.
- Not be different responses depending on the invoker. For example, this can occur when the responses
is specific to a resource owner (such as a user for
user/basicwhen not providing a user touser/{id}/basic). - Not have an additional permission required such as faction API access.
@spec remove( state :: state(), execution_unit :: Tornex.Scheduler.ExecutionUnit.t() | Tornex.SpecQuery.t() ) :: state()
Traverse the state tree and remove the branches that are being fulfilled by the
Tornex.Scheduler.ExecutionUnit.
After removing the queries being fulfilled from the branches of the state tree, the function will also prune the tree of any branches related to the queries if there are no queries retaining them.
@spec start_link(opts :: keyword()) :: GenServer.on_start()
Start the Tornex.Scheduler.QueryRegistry GenServer.