couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r936889 - in /couchdb/trunk: share/server/filter.js share/www/script/test/changes.js src/couchdb/couch_query_servers.erl
Date Thu, 22 Apr 2010 15:08:08 GMT
Author: jchris
Date: Thu Apr 22 15:08:08 2010
New Revision: 936889

URL: http://svn.apache.org/viewvc?rev=936889&view=rev
Log:
fix erlang filter funs and normalize filter fun api. thanks fdmanana. closes COUCHDB-740

Modified:
    couchdb/trunk/share/server/filter.js
    couchdb/trunk/share/www/script/test/changes.js
    couchdb/trunk/src/couchdb/couch_query_servers.erl

Modified: couchdb/trunk/share/server/filter.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/server/filter.js?rev=936889&r1=936888&r2=936889&view=diff
==============================================================================
--- couchdb/trunk/share/server/filter.js (original)
+++ couchdb/trunk/share/server/filter.js Thu Apr 22 15:08:08 2010
@@ -15,9 +15,8 @@ var Filter = {
     var results = [];
     var docs = args[0];
     var req = args[1];
-    var userCtx = args[2];
     for (var i=0; i < docs.length; i++) {
-      results.push((fun.apply(ddoc, [docs[i], req, userCtx]) && true) || false);
+      results.push((fun.apply(ddoc, [docs[i], req]) && true) || false);
     };
     respond([true, results]);
   }

Modified: couchdb/trunk/share/www/script/test/changes.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/changes.js?rev=936889&r1=936888&r2=936889&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/changes.js (original)
+++ couchdb/trunk/share/www/script/test/changes.js Thu Apr 22 15:08:08 2010
@@ -347,5 +347,44 @@ couchTests.changes = function(debug) {
   req = CouchDB.request("GET", "/test_suite_db/_changes?filter=changes_filter/conflicted");
   resp = JSON.parse(req.responseText);
   T(resp.results.length == 1);
+
+  // test with erlang filter function
+  run_on_modified_server([{
+    section: "native_query_servers",
+    key: "erlang",
+    value: "{couch_native_process, start_link, []}"
+  }], function() {
+    var erl_ddoc = {
+      _id: "_design/erlang",
+      language: "erlang",
+      filters: {
+        foo:
+          'fun({Doc}, Req) -> ' +
+          '  Value = proplists:get_value(<<"value">>, Doc),' +
+          '  (Value rem 2) =:= 0' +
+          'end.'
+      }
+    };
+
+    db.deleteDb();
+    db.createDb();
+    T(db.save(erl_ddoc).ok);
+
+    var req = CouchDB.request("GET", "/test_suite_db/_changes?filter=erlang/foo");
+    var resp = JSON.parse(req.responseText);
+    T(resp.results.length === 0);
+
+    T(db.save({_id: "doc1", value : 1}).ok);
+    T(db.save({_id: "doc2", value : 2}).ok);
+    T(db.save({_id: "doc3", value : 3}).ok);
+    T(db.save({_id: "doc4", value : 4}).ok);
+
+    var req = CouchDB.request("GET", "/test_suite_db/_changes?filter=erlang/foo");
+    var resp = JSON.parse(req.responseText);
+    T(resp.results.length === 2);
+    T(resp.results[0].id === "doc2");
+    T(resp.results[1].id === "doc4");
+  });
+
 };
 

Modified: couchdb/trunk/src/couchdb/couch_query_servers.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_query_servers.erl?rev=936889&r1=936888&r2=936889&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_query_servers.erl (original)
+++ couchdb/trunk/src/couchdb/couch_query_servers.erl Thu Apr 22 15:08:08 2010
@@ -208,8 +208,7 @@ filter_docs(Req, Db, DDoc, FName, Docs) 
         couch_httpd_external:json_req_obj(HttpReq, Db)
     end,
     JsonDocs = [couch_doc:to_json_obj(Doc, [revs]) || Doc <- Docs],
-    JsonCtx = couch_util:json_user_ctx(Db),
-    [true, Passes] = ddoc_prompt(DDoc, [<<"filters">>, FName], [JsonDocs, JsonReq,
JsonCtx]),
+    [true, Passes] = ddoc_prompt(DDoc, [<<"filters">>, FName], [JsonDocs, JsonReq]),
     {ok, Passes}.
 
 ddoc_proc_prompt({Proc, DDocId}, FunPath, Args) -> 



Mime
View raw message