blogit v1.2.1 Blogit.Components.Metas View Source

A Blogit.Component process which can be queried from outside. The Blogit.Components.Metas process holds the meta data for all the posts in the blog as its state.

For some queries only the meta data of the posts is needed and quering this component for it is cheaper than retrieving it from the Blogit.Components.Posts one. Also the messages with only meta data are much smaller, as they only include the preview HTML of the posts and not the whole content.

This process handles the following call messages:

  • {:list, from, size} -> returns a list of post metas sorted by their created_at field, newest first. The first from are dropped and the size of the result list is specified by size. The size can be :infinity.
  • :list_pinned -> returns a list of tuples representing posts, sorted by the post’s meta.updated_at field, newest first, only if their pinned field is true. The tuples consist of two elements the first is the uniq name of the post and the second - its title.

This component is supervised by Blogit.Components.Supervisor and added to it by Blogit.Server. When the posts get updated, this process’ state is reset to nil and on the next request to it, it is re-calculated.

Link to this section Summary

Functions

Returns the base name, which identifies the process. For example it could be posts

Invoked when the server is started. start_link/3 or start/3 will block until it returns

Returns the name, which identifies the process. It is composed using the base_name/0 and the given language. For example if the base_name/0 returns posts and the given language is en, the name will be posts_en

Link to this section Functions

Returns the base name, which identifies the process. For example it could be posts.

Invoked when the server is started. start_link/3 or start/3 will block until it returns.

args is the argument term (second argument) passed to start_link/3.

Returning {:ok, state} will cause start_link/3 to return {:ok, pid} and the process to enter its loop.

Returning {:ok, state, timeout} is similar to {:ok, state} except handle_info(:timeout, state) will be called after timeout milliseconds if no messages are received within the timeout.

Returning {:ok, state, :hibernate} is similar to {:ok, state} except the process is hibernated before entering the loop. See c:handle_call/3 for more information on hibernation.

Returning :ignore will cause start_link/3 to return :ignore and the process will exit normally without entering the loop or calling c:terminate/2. If used when part of a supervision tree the parent supervisor will not fail to start nor immediately try to restart the GenServer. The remainder of the supervision tree will be (re)started and so the GenServer should not be required by other processes. It can be started later with Supervisor.restart_child/2 as the child specification is saved in the parent supervisor. The main use cases for this are:

  • The GenServer is disabled by configuration but might be enabled later.
  • An error occurred and it will be handled by a different mechanism than the Supervisor. Likely this approach involves calling Supervisor.restart_child/2 after a delay to attempt a restart.

Returning {:stop, reason} will cause start_link/3 to return {:error, reason} and the process to exit with reason reason without entering the loop or calling c:terminate/2.

Callback implementation for GenServer.init/1.

Returns the name, which identifies the process. It is composed using the base_name/0 and the given language. For example if the base_name/0 returns posts and the given language is en, the name will be posts_en.

The worker id registered under the Blogit.Components.Supervisor will be the name returned by this function, when start_link/1 is called to create the process. The language passed to it (or the one returned from Blogit.Settings.default_language/0) will be passed to name/1 to create the name.

Link to this function start_link(language \\ Settings.default_language(), state_provider \\ Blogit.Server) View Source

Starts the GenServer process.

The process is started and supervised by Blogit.Components.Supervisor and the specification of it is added by Blogit.Server.

The state of the process in the beginning is nil.

The process should keep the given language passed to init/1 as the first of a tuple as part of its state. This process should serve requests related to that language.

The given state_provider is the second element of the tuple passed to GenServer.init/1. It could be used to retrieve the state of the process.

By default the language is the one returned by Blogit.Settings.default_language/0 and the state_provider is Blogit.Server.