rnewson commented on code in PR #4735:
URL: https://github.com/apache/couchdb/pull/4735#discussion_r1321494553


##########
src/mango/src/mango_cursor_view.erl:
##########
@@ -337,19 +349,48 @@ choose_best_index(IndexRanges) ->
     {SelectedIndex, SelectedIndexRanges, _} = hd(lists:sort(Cmp, IndexRanges)),
     {SelectedIndex, SelectedIndexRanges}.
 
+-spec format_stats(RawStats, Options) -> FormattedStats when
+    RawStats :: shard_stats_v2(),
+    Options :: mrargs_extra(),
+    FormattedStats :: shard_stats_v1() | shard_stats_v2().
+format_stats(Stats, Options) ->
+    case couch_util:get_value(execution_stats_map, Options, false) of
+        true ->
+            Stats;
+        false ->
+            DocsExamined = maps:get(docs_examined, Stats),
+            {docs_examined, DocsExamined}
+    end.
+
+-spec roll_stats(Stats, Options) -> ok when
+    Stats :: shard_stats_v2(),
+    Options :: mrargs_extra().
+roll_stats(Stats, Options) ->
+    case couch_util:get_value(execution_stats_rolling, Options, false) of
+        true ->
+            ok = rexi:stream2({execution_stats, format_stats(Stats, Options)});
+        false ->
+            KeysExamined = maps:get(keys_examined, Stats),
+            DocsExamined = maps:get(docs_examined, Stats),
+            mango_execution_stats:shard_incr_keys_examined(KeysExamined),
+            mango_execution_stats:shard_incr_docs_examined(DocsExamined)
+    end.
+
 -spec view_cb
     (Message, #mrargs{}) -> Response when
         Message :: {meta, any()} | {row, row_properties()} | complete,
         Response :: {ok, #mrargs{}};
     (ok, ddoc_updated) -> any().
-view_cb({meta, Meta}, Acc) ->
+view_cb({meta, Meta}, #mrargs{extra = Options} = Acc) ->
     % Map function starting
-    mango_execution_stats:shard_init(),
+    case couch_util:get_value(execution_stats_rolling, Options, false) of

Review Comment:
   I'd pull this logic into its own function to keep the callbacks short.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to