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

* src/ejabberd_auth.erl: Added get_vh_registered_users_number/1

function
* src/ejabberd_auth_odbc.erl: Likewise
* src/odbc/odbc_queries.erl: Added users_number/1 function
* src/ejabberd.cfg.example: Added an example for
pgsql_users_number_estimate option

SVN Revision: 766
This commit is contained in:
Alexey Shchepin 2007-05-12 18:09:38 +00:00
parent a10923c197
commit 8aab10d28c
5 changed files with 50 additions and 2 deletions

View File

@ -1,5 +1,12 @@
2007-05-12 Alexey Shchepin <alexey@sevcom.net>
* src/ejabberd_auth.erl: Added get_vh_registered_users_number/1
function
* src/ejabberd_auth_odbc.erl: Likewise
* src/odbc/odbc_queries.erl: Added users_number/1 function
* src/ejabberd.cfg.example: Added an example for
pgsql_users_number_estimate option
* src/ejabberd_auth_anonymous.erl: Added anonymous_purge_hook
(thanks to Christophe Romain and Mickael Remond)
* src/mod_offline.erl: Likewise

View File

@ -96,6 +96,10 @@
%{auth_method, odbc}.
%{odbc_server, "DSN=ejabberd;UID=ejabberd;PWD=ejabberd"}.
% Uncomment this if you are using postgres, having a large DB, and need a
% faster but inexact replacement for "select count(*) from users"
%{pgsql_users_number_estimate, true}.
% Host name:
{hosts, ["localhost"]}.

View File

@ -22,6 +22,7 @@
try_register/3,
dirty_get_registered_users/0,
get_vh_registered_users/1,
get_vh_registered_users_number/1,
get_password/2,
get_password_s/2,
is_user_exists/2,
@ -107,6 +108,19 @@ get_vh_registered_users(Server) ->
M:get_vh_registered_users(Server)
end, auth_modules(Server)).
get_vh_registered_users_number(Server) ->
lists:sum(
lists:map(
fun(M) ->
case erlang:function_exported(
M, get_vh_registered_users_number, 1) of
true ->
M:get_vh_registered_users_number(Server);
false ->
length(M:get_vh_registered_users(Server))
end
end, auth_modules(Server))).
get_password(User, Server) ->
lists:foldl(
fun(M, false) ->

View File

@ -18,6 +18,7 @@
try_register/3,
dirty_get_registered_users/0,
get_vh_registered_users/1,
get_vh_registered_users_number/1,
get_password/2,
get_password_s/2,
is_user_exists/2,
@ -28,8 +29,6 @@
-include("ejabberd.hrl").
-record(passwd, {user, password}).
%%%----------------------------------------------------------------------
%%% API
%%%----------------------------------------------------------------------
@ -123,6 +122,15 @@ get_vh_registered_users(Server) ->
[]
end.
get_vh_registered_users_number(Server) ->
LServer = jlib:nameprep(Server),
case catch odbc_queries:users_number(LServer) of
{selected, [_], [{Res}]} ->
list_to_integer(Res);
_ ->
0
end.
get_password(User, Server) ->
case jlib:nodeprep(User) of
error ->

View File

@ -15,6 +15,7 @@
del_user/2,
del_user_return_password/3,
list_users/1,
users_number/1,
add_spool_sql/2,
add_spool/2,
get_and_del_spool_msg_t/2,
@ -109,6 +110,20 @@ list_users(LServer) ->
LServer,
"select username from users").
users_number(LServer) ->
case ejabberd_config:get_local_option(
{pgsql_users_number_estimate, LServer}) of
true ->
ejabberd_odbc:sql_query(
LServer,
"select reltuples from pg_class "
"where oid = 'users'::regclass::oid");
_ ->
ejabberd_odbc:sql_query(
LServer,
"select count(*) from users")
end.
add_spool_sql(Username, XML) ->
["insert into spool(username, xml) "
"values ('", Username, "', '",