You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ii...@apache.org on 2022/02/10 19:33:20 UTC

[couchdb] branch 3.x updated: Add couch_mrview_debug:view_signature/2

This is an automated email from the ASF dual-hosted git repository.

iilyak pushed a commit to branch 3.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/3.x by this push:
     new ea15c86  Add couch_mrview_debug:view_signature/2
     new d97b5ce  Merge pull request #3929 from cloudant/add-couch_mrview_debug
ea15c86 is described below

commit ea15c8689bd2f79fb231148b76de430bb37cdad4
Author: ILYA Khlopotov <ii...@apache.org>
AuthorDate: Wed Feb 9 11:53:17 2022 -0800

    Add couch_mrview_debug:view_signature/2
---
 src/couch_mrview/src/couch_mrview_debug.erl | 50 +++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/src/couch_mrview/src/couch_mrview_debug.erl b/src/couch_mrview/src/couch_mrview_debug.erl
new file mode 100644
index 0000000..a4203d4
--- /dev/null
+++ b/src/couch_mrview/src/couch_mrview_debug.erl
@@ -0,0 +1,50 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_mrview_debug).
+
+-export([
+    help/0,
+    help/1
+]).
+
+-export([
+    view_signature/2
+]).
+
+-include_lib("couch_mrview/include/couch_mrview.hrl").
+
+help() ->
+    [
+        view_signature
+    ].
+
+-spec help(Function :: atom()) -> ok.
+%% erlfmt-ignore
+help(view_signature) ->
+    io:format("
+    view_signature(ShardName, DDocName)
+    --------------
+    Returns a view signature for given ddoc for a given (non clustered) database.
+    ---
+    ", []);
+help(Unknown) ->
+    io:format("Unknown function: `~p`. Please try one of the following:~n", [Unknown]),
+    [io:format("    - ~s~n", [Function]) || Function <- help()],
+    io:format("    ---~n", []),
+    ok.
+
+view_signature(DbName, DDocName) ->
+    {ok, Db} = couch_db:open_int(DbName, []),
+    {ok, DDoc} = couch_db:open_doc_int(Db, <<"_design/", DDocName/binary>>, []),
+    {ok, IdxState} = couch_mrview_util:ddoc_to_mrst(DDocName, DDoc),
+    couch_util:to_hex(IdxState#mrst.sig).