Skip to content

Fix strategy fifo as default if not defined. #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
2 commits merged into from
Mar 3, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/mysql_poolboy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

%% @doc Adds a pool to the started mysql_poolboy application.
add_pool(PoolName, PoolArgs, MysqlArgs) ->
%% We want strategy fifo as default instead of lifo.
PoolSpec = child_spec(PoolName, PoolArgs, MysqlArgs),
supervisor:start_child(mysql_poolboy_sup, PoolSpec).

Expand All @@ -44,8 +45,15 @@ checkout(PoolName) ->
%% @doc Creates a supvervisor:child_spec. When the need to
%% supervise the pools in another way.
child_spec(PoolName, PoolArgs, MysqlArgs) ->
PoolArgs1 =
[{name, {local, PoolName}}, {worker_module, mysql}] ++ PoolArgs,
PoolArgs1 = case proplists:is_defined(strategy, PoolArgs) of
true ->
[{name, {local, PoolName}}, {worker_module, mysql} | PoolArgs];
false ->
%% Use fifo by default. MySQL closes unused connections after a certain time.
%% Fifo causes all connections to be regularily used which prevents them from
%% being closed.,
[{strategy, fifo}, {name, {local, PoolName}}, {worker_module, mysql} | PoolArgs]
end,
poolboy:child_spec(PoolName, PoolArgs1, MysqlArgs).

%% @doc Execute a mysql prepared statement with given params.
Expand Down