object: split object_cache from user_cache
[akkoma] / lib / pleroma / application.ex
1 defmodule Pleroma.Application do
2 use Application
3
4 # See http://elixir-lang.org/docs/stable/elixir/Application.html
5 # for more information on OTP Applications
6 def start(_type, _args) do
7 import Supervisor.Spec
8 import Cachex.Spec
9
10 # Define workers and child supervisors to be supervised
11 children =
12 [
13 # Start the Ecto repository
14 supervisor(Pleroma.Repo, []),
15 # Start the endpoint when the application starts
16 supervisor(Pleroma.Web.Endpoint, []),
17 # Start your own worker by calling: Pleroma.Worker.start_link(arg1, arg2, arg3)
18 # worker(Pleroma.Worker, [arg1, arg2, arg3]),
19 worker(
20 Cachex,
21 [
22 :user_cache,
23 [
24 default_ttl: 25000,
25 ttl_interval: 1000,
26 limit: 2500
27 ]
28 ],
29 id: :cachex_user
30 ),
31 worker(
32 Cachex,
33 [
34 :object_cache,
35 [
36 default_ttl: 25000,
37 ttl_interval: 1000,
38 limit: 2500
39 ]
40 ],
41 id: :cachex_object
42 ),
43 worker(
44 Cachex,
45 [
46 :idempotency_cache,
47 [
48 expiration:
49 expiration(
50 default: :timer.seconds(6 * 60 * 60),
51 interval: :timer.seconds(60)
52 ),
53 limit: 2500
54 ]
55 ],
56 id: :cachex_idem
57 ),
58 worker(Pleroma.Web.Federator, []),
59 worker(Pleroma.Gopher.Server, []),
60 worker(Pleroma.Stats, [])
61 ] ++
62 if Mix.env() == :test,
63 do: [],
64 else:
65 [worker(Pleroma.Web.Streamer, [])] ++
66 if(
67 !chat_enabled(),
68 do: [],
69 else: [worker(Pleroma.Web.ChatChannel.ChatChannelState, [])]
70 )
71
72 # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
73 # for other strategies and supported options
74 opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
75 Supervisor.start_link(children, opts)
76 end
77
78 defp chat_enabled do
79 Application.get_env(:pleroma, :chat, []) |> Keyword.get(:enabled)
80 end
81 end