couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [couchdb] 04/12: Pass the DB record to index validation functions
Date Tue, 27 Nov 2018 20:37:59 GMT
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch feature/partitioned-databases
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit f9743a74b813849f1631b9f193e2be89a11018d7
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
AuthorDate: Wed Oct 24 11:12:27 2018 -0500

    Pass the DB record to index validation functions
    
    Allow index validation to be parameterized by the database without
    having to reopen its own copy.
---
 src/couch/src/couch_db.erl                 | 6 +++---
 src/couch_index/src/couch_index_server.erl | 4 ++--
 src/couch_mrview/src/couch_mrview.erl      | 9 ++++++---
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index f3aeb15..9355422 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -829,7 +829,7 @@ group_alike_docs([Doc|Rest], [Bucket|RestBuckets]) ->
 
 validate_doc_update(#db{}=Db, #doc{id= <<"_design/",_/binary>>}=Doc, _GetDiskDocFun)
->
     case catch check_is_admin(Db) of
-        ok -> validate_ddoc(Db#db.name, Doc);
+        ok -> validate_ddoc(Db, Doc);
         Error -> Error
     end;
 validate_doc_update(#db{validate_doc_funs = undefined} = Db, Doc, Fun) ->
@@ -847,9 +847,9 @@ validate_doc_update(Db, Doc, GetDiskDocFun) ->
             validate_doc_update_int(Db, Doc, GetDiskDocFun)
     end.
 
-validate_ddoc(DbName, DDoc) ->
+validate_ddoc(Db, DDoc) ->
     try
-        ok = couch_index_server:validate(DbName, couch_doc:with_ejson_body(DDoc))
+        ok = couch_index_server:validate(Db, couch_doc:with_ejson_body(DDoc))
     catch
         throw:{invalid_design_doc, Reason} ->
             {bad_request, invalid_design_doc, Reason};
diff --git a/src/couch_index/src/couch_index_server.erl b/src/couch_index/src/couch_index_server.erl
index a33c1e4..49d1e61 100644
--- a/src/couch_index/src/couch_index_server.erl
+++ b/src/couch_index/src/couch_index_server.erl
@@ -41,7 +41,7 @@ start_link() ->
     gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
 
 
-validate(DbName, DDoc) ->
+validate(Db, DDoc) ->
     LoadModFun = fun
         ({ModNameList, "true"}) ->
             try
@@ -54,7 +54,7 @@ validate(DbName, DDoc) ->
     end,
     ValidateFun = fun
         (ModName) ->
-            ModName:validate(DbName, DDoc)
+            ModName:validate(Db, DDoc)
     end,
     EnabledIndexers = lists:flatmap(LoadModFun, config:get("indexers")),
     lists:foreach(ValidateFun, EnabledIndexers).
diff --git a/src/couch_mrview/src/couch_mrview.erl b/src/couch_mrview/src/couch_mrview.erl
index f6462e1..d5b01ed 100644
--- a/src/couch_mrview/src/couch_mrview.erl
+++ b/src/couch_mrview/src/couch_mrview.erl
@@ -169,7 +169,7 @@ join([H|T], Sep, Acc) ->
     join(T, Sep, [Sep, H | Acc]).
 
 
-validate(DbName,  DDoc) ->
+validate(Db,  DDoc) ->
     ok = validate_ddoc_fields(DDoc#doc.body),
     GetName = fun
         (#mrview{map_names = [Name | _]}) -> Name;
@@ -194,8 +194,11 @@ validate(DbName,  DDoc) ->
                 couch_query_servers:try_compile(Proc, reduce, RedName, RedSrc)
         end, Reds)
     end,
-    {ok, #mrst{language=Lang, views=Views}}
-            = couch_mrview_util:ddoc_to_mrst(DbName, DDoc),
+    {ok, #mrst{
+        language = Lang,
+        views = Views
+    }} = couch_mrview_util:ddoc_to_mrst(couch_db:name(Db), DDoc),
+
     try Views =/= [] andalso couch_query_servers:get_os_process(Lang) of
         false ->
             ok;


Mime
View raw message