]> granicus.if.org Git - ejabberd/commitdiff
Optimized mod_roster_odbc:get_roster
authorAlexey Shchepin <alexey@process-one.net>
Wed, 29 Jun 2011 08:56:23 +0000 (11:56 +0300)
committerAlexey Shchepin <alexey@process-one.net>
Wed, 29 Jun 2011 08:56:23 +0000 (11:56 +0300)
src/mod_roster_odbc.erl

index 936d3cff264add93e41b610b55d733c2ea3088b5..b713a0aab08fcbf60a757b57a6d1053b558684f6 100644 (file)
@@ -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),