You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2021/03/31 06:21:37 UTC

[GitHub] [couchdb] iilyak edited a comment on pull request #3481: Validate ddoc uses couch_eval

iilyak edited a comment on pull request #3481:
URL: https://github.com/apache/couchdb/pull/3481#issuecomment-810801703


   There are very few places where we need to call `acquire_context/1` and `release_context/1` so I am ok with proposed change. However I wanted to make sure you did consider a different option, which is something like the following:
   
   ```
   -module(couch_eval).
   
   -map_docs/2
   +map_docs/2,
   +with_context/2,
   +try_compile/3
   
   with_context(#{language := Language}, Fun) ->
       case acquire_context(Language) of
       try acquire_context(Language) of
           {ok, Ctx} -> Fun(Ctx)
       after
           release_context(Ctx)
       end.
       
   
   %% this would be private function
   acquire_context(Language) ->
       ApiMod = get_api_mod(Language),
       {ok, Ctx} = ApiMod:acquire_context(),
       {ok, {ApiMod, Ctx}}.
   ```
   
   Then the caller would look like:
   
   ```
   -module(couch_mrview).
   
   validate(DbName, _IsDbPartitioned,  DDoc) ->
       ...
       Views =/= [] andalso couch_eval:with_context(#{language => Lang}, fun(Ctx) ->
            lists:foreach(fun(V) -> ValidateView(Ctx, V) end, Views)     
       end),
       ok.
   ```


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org