From 60009ece441713028576ba4d3e161aae8b79e68c Mon Sep 17 00:00:00 2001 From: Alexey Shchepin Date: Wed, 29 Jun 2011 11:56:23 +0300 Subject: [PATCH] Optimized mod_roster_odbc:get_roster --- src/mod_roster_odbc.erl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/mod_roster_odbc.erl b/src/mod_roster_odbc.erl index 936d3cff2..b713a0aab 100644 --- a/src/mod_roster_odbc.erl +++ b/src/mod_roster_odbc.erl @@ -249,6 +249,11 @@ get_roster(LUser, LServer) -> _ -> [] end, + GroupsDict = + lists:foldl( + fun({J, G}, Acc) -> + dict:append(J, G, Acc) + end, dict:new(), JIDGroups), RItems = lists:flatmap( fun(I) -> case raw_to_record(LServer, I) of @@ -257,12 +262,11 @@ get_roster(LUser, LServer) -> []; R -> SJID = jlib:jid_to_string(R#roster.jid), - Groups = lists:flatmap( - fun({S, G}) when S == SJID -> - [G]; - (_) -> - [] - end, JIDGroups), + Groups = + case dict:find(SJID, GroupsDict) of + {ok, Gs} -> Gs; + error -> [] + end, [R#roster{groups = Groups}] end end, Items),