MishkaCmsCore.Runtime.States.RedirectsState (Mishka CMS Core v0.0.1)

Copy Markdown View Source

ETS copy of the active MishkaCmsCore.Runtime.Redirect rules, so a request is answered without a query.

The same shape as MishkaCmsCore.Runtime.States.TranslationsState, for the same reasons: loaded once at boot, then kept current off the resource's own PubSub broadcasts, which reach every node — a rule saved on one server is served by all of them without a restart. Nothing is read again until a rule changes.

Each entry is {{site_id, from_path}, id, to, status}; a second table maps a rule's id to its key, so a rule whose from_path changed, or that was archived, deactivated or deleted, leaves its old key behind it. Only active, unarchived rules are kept.

Every change is heard on runtime:state:redirect:changed with %{op: :save | :delete, key: id}.

Started by the host after Phoenix.PubSub and before the endpoint, like the other states:

MishkaCmsCore.Runtime.States.RedirectsState,

Summary

Functions

Returns a specification to start this module under a supervisor.

The rule site_id serves for path — a key MishkaCmsCore.Runtime.Redirects built — as {to, status}, else nil.

Reload every rule from the database.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

lookup(site_id, path)

@spec lookup(String.t(), String.t()) :: {String.t(), pos_integer()} | nil

The rule site_id serves for path — a key MishkaCmsCore.Runtime.Redirects built — as {to, status}, else nil.

One lookup, no GenServer hop. Never raises: a table that is not there yet is the same as one with nothing in it, so a request answered before this process starts is served as if no rule existed.

refresh()

@spec refresh() :: :ok

Reload every rule from the database.

start_link(opts \\ [])