25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Cache 'isuser' queries to external auth program

This commit is contained in:
Evgeniy Khramtsov 2018-02-16 20:50:22 +03:00
parent f5d208441d
commit cffdb06b66

View File

@ -526,7 +526,10 @@ db_get_password(User, Server, Mod) ->
UseCache = use_cache(Mod, Server),
case erlang:function_exported(Mod, get_password, 2) of
false when UseCache ->
ets_cache:lookup(?AUTH_CACHE, {User, Server});
case ets_cache:lookup(?AUTH_CACHE, {User, Server}) of
{ok, exists} -> error;
Other -> Other
end;
false ->
error;
true when UseCache ->
@ -544,7 +547,20 @@ db_user_exists(User, Server, Mod) ->
error ->
case Mod:store_type(Server) of
external ->
Mod:user_exists(User, Server);
case ets_cache:update(
?AUTH_CACHE, {User, Server}, {ok, exists},
fun() ->
case Mod:user_exists(User, Server) of
true -> {ok, exists};
false -> error;
{error, _} = Err -> Err
end
end, cache_nodes(Mod, Server)) of
{ok, _} ->
true;
error ->
false
end;
_ ->
false
end