On Tue, Nov 30, 2010 at 12:22 PM, Filipe David Manana <fdman...@apache.org> wrote: > Hi Benoît, > > It's a good idea I think. Good work. > I have some comments regarding the patch: > > 1) Doing a regexp substitution of the view function's code string > seems like a recipe for disaster to me. > > I think the safe and clean way to go here is to create another > sandbox, with a different 'emit' function, and in > Couch.compileFunction (utils.js) pass a third and optional argument > which is the context in which the function is going to be executed. If > omitted, it uses 'sandbox' as the context, otherwise use that other > context. Then here: > > https://github.com/benoitc/couchdb/commit/651e29e1bb767fb493bf75497623dae89bf9a5ad#L0R34 > > You would so something like: > > fun = Couch.compileFunction(source, filter_sandbox); > > > 2) Don't forget the indentation level for .js files is 2 spaces (I'm > seeing a mix of 4 and 2 spaces in share/server/filter.js) > > 3) Avoid the unnecessary white-space only changes: > > https://github.com/benoitc/couchdb/commit/651e29e1bb767fb493bf75497623dae89bf9a5ad#L2R396 > https://github.com/benoitc/couchdb/commit/651e29e1bb767fb493bf75497623dae89bf9a5ad#L2R477 > https://github.com/benoitc/couchdb/commit/651e29e1bb767fb493bf75497623dae89bf9a5ad#L3R255 > https://github.com/benoitc/couchdb/commit/651e29e1bb767fb493bf75497623dae89bf9a5ad#L4R60 > https://github.com/benoitc/couchdb/commit/651e29e1bb767fb493bf75497623dae89bf9a5ad#L4R85 > https://github.com/benoitc/couchdb/commit/651e29e1bb767fb493bf75497623dae89bf9a5ad#L4R247 > https://github.com/benoitc/couchdb/commit/651e29e1bb767fb493bf75497623dae89bf9a5ad#L4R503 > https://github.com/benoitc/couchdb/commit/651e29e1bb767fb493bf75497623dae89bf9a5ad#L3R191 > > 4) This?LOG_INFO line is there for your debugging purposes I think > (should be removed): > > https://github.com/benoitc/couchdb/commit/651e29e1bb767fb493bf75497623dae89bf9a5ad#L3R168 > > > cheers > > On Mon, Nov 29, 2010 at 10:05 PM, Benoit Chesneau <bchesn...@gmail.com> wrote: >> Hi all, >> >> Tonight i've written t quick patch that allows the user to use map >> view function to filter changes. Here is the patch : >> >> https://github.com/benoitc/couchdb/commit/651e29e1bb767fb493bf75497623dae89bf9a5ad >> >> thoughts ? >> >> - benoît >> > > > > -- > Filipe David Manana, > fdman...@gmail.com, fdman...@apache.org > > "Reasonable men adapt themselves to the world. > Unreasonable men adapt the world to themselves. > That's why all progress depends on unreasonable men." >
Here is an updated patch. It now use a filter sandbox instead of patching the function and it fixes whitespaces. https://github.com/benoitc/couchdb/compare/master...view_changes Description of this patch: Allows to use view map functions to filter database changes. Each time a map function function could have emitted a pair of key value for a doc, a change is emitted. This is another builtin change filter. Query parameters are : filter=_view view = designame/viewname Url: http://host/db/_changes?filter=_view&view=designame/viewname ok for you? - benoît