Hi there,
I use Cachex to cache very frequent queries:
@spec get_setting_for_forum(%Forum{}) :: %Setting{} | nil
def get_setting_for_forum(%Forum{} = forum) do
Cachex.fetch!(:cforum, "settings/forums/#{forum.forum_id}", fn ->
from(setting in Setting, where: setting.forum_id == ^forum.forum_id)
|> Repo.one()
end)
end
@spec get_setting_for_user(%User{}) :: %Setting{} | nil
def get_setting_for_user(%User{} = user) do
Cachex.fetch!(:cforum, "settings/users/#{user.user_id}", fn ->
from(setting in Setting, where: setting.user_id == ^user.user_id)
|> Repo.one()
end)
end
This function loads a settings object from the database. It works fine in production and dev code, but in tests I get this error:
** (Cachex.ExecutionError) connection not available and request was dropped from queue after 602ms. You can configure how long requests wait in the queue using :queue_target and :queue_interval. See DBConnection.start_link/2 for more information
I call the getter functions like this:
def load_relevant_settings(forum, user)
def load_relevant_settings(nil, nil) do
[get_global_setting()]
|> Enum.reject(&is_nil(&1))
end
def load_relevant_settings(%Forum{} = forum, nil) do
[get_global_setting(), get_setting_for_forum(forum)]
|> Enum.reject(&is_nil(&1))
end
def load_relevant_settings(nil, %User{} = user) do
[get_global_setting(), get_setting_for_user(user)]
|> Enum.reject(&is_nil(&1))
end
def load_relevant_settings(%Forum{} = forum, %User{} = user) do
[get_global_setting(), get_setting_for_forum(forum), get_setting_for_user(user)]
|> Enum.reject(&is_nil(&1))
end
I can’t figure out what’s going wrong. Has anybody an idea?
Edit: I already tried to set the pool size to a very high value (100), but it didn’t help.
Best regards,
CK