]> granicus.if.org Git - ejabberd/commitdiff
Cache 'isuser' queries to external auth program
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Fri, 16 Feb 2018 17:50:22 +0000 (20:50 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Fri, 16 Feb 2018 17:50:22 +0000 (20:50 +0300)
src/ejabberd_auth.erl

index df75be9eb7aa8df56cfd98992eb9c42f325a55f8..03eee9de480b0f1a17fe802d9937a5410a668b43 100644 (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