couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [13/14] couch-stats commit: updated refs/heads/master to bb24add
Date Wed, 20 Aug 2014 13:09:21 GMT
Simplify couch_stats_aggregator:reload_metrics/0

h/t davisp


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/commit/30fd32cb
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/tree/30fd32cb
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/diff/30fd32cb

Branch: refs/heads/master
Commit: 30fd32cb12ab7707ce97efd66215921bb1bb4ea3
Parents: 6efb035
Author: Benjamin Anderson <b@banjiewen.net>
Authored: Wed Feb 12 09:32:22 2014 -0800
Committer: Robert Newson <rnewson@apache.org>
Committed: Tue Aug 19 14:48:31 2014 +0100

----------------------------------------------------------------------
 src/couch_stats_aggregator.erl | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/blob/30fd32cb/src/couch_stats_aggregator.erl
----------------------------------------------------------------------
diff --git a/src/couch_stats_aggregator.erl b/src/couch_stats_aggregator.erl
index 09ca572..4c7168d 100644
--- a/src/couch_stats_aggregator.erl
+++ b/src/couch_stats_aggregator.erl
@@ -68,25 +68,24 @@ code_change(_OldVsn, State, _Extra) ->
     {ok, State}.
 
 reload_metrics() ->
-    Existing = couch_stats:list(),
     Current = load_metrics_for_applications(),
-    ToDelete = lists:foldl(
-        fun({Name, Props}=Stat, Acc) ->
+    CurrentSet = sets:from_list(Current),
+    ExistingSet = sets:from_list(couch_stats:list()),
+    ToDelete = sets:subtract(ExistingSet, CurrentSet),
+    ToCreate = sets:subtract(CurrentSet, ExistingSet),
+    sets:fold(
+        fun({Name, _}, _) -> couch_stats:delete(Name), nil end,
+        nil,
+        ToDelete
+    ),
+    sets:fold(
+        fun({Name, Props}, _) ->
             Type = proplists:get_value(type, Props),
-            case sets:is_element(Stat, Acc) of
-                true ->
-                    sets:del_element(Stat, Acc);
-                false ->
-                    couch_stats:new(Type, Name),
-                    Acc
-            end
+            couch_stats:new(Type, Name),
+            nil
         end,
-        sets:from_list(Existing),
-        Current
-    ),
-    lists:foreach(
-        fun({Name, _}) -> couch_stats:delete(Name) end,
-        sets:to_list(ToDelete)
+        nil,
+        ToCreate
     ),
     {ok, Current}.
 


Mime
View raw message