couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1040478 - in /couchdb/branches/new_replicator: share/www/script/test/changes.js src/couchdb/couch_changes.erl src/couchdb/couch_httpd_db.erl
Date Tue, 30 Nov 2010 12:17:09 GMT
Author: fdmanana
Date: Tue Nov 30 12:17:09 2010
New Revision: 1040478

URL: http://svn.apache.org/viewvc?rev=1040478&view=rev
Log:
Merged revision 1022291 from trunk: get _changes on specific docids

/POST /db/_changes
{"doc_ids": ["docid1", ...]}

Modified:
    couchdb/branches/new_replicator/share/www/script/test/changes.js
    couchdb/branches/new_replicator/src/couchdb/couch_changes.erl
    couchdb/branches/new_replicator/src/couchdb/couch_httpd_db.erl

Modified: couchdb/branches/new_replicator/share/www/script/test/changes.js
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/share/www/script/test/changes.js?rev=1040478&r1=1040477&r2=1040478&view=diff
==============================================================================
--- couchdb/branches/new_replicator/share/www/script/test/changes.js (original)
+++ couchdb/branches/new_replicator/share/www/script/test/changes.js Tue Nov 30 12:17:09 2010
@@ -175,6 +175,8 @@ couchTests.changes = function(debug) {
     T(change.id == "barz");
     T(change.changes[0].rev == docBarz._rev);
     T(lines[3]=='"last_seq":4}');
+
+
   }
   
   // test the filtered changes
@@ -390,6 +392,57 @@ couchTests.changes = function(debug) {
     T(resp.results.length === 2);
     T(resp.results[0].id === "doc2");
     T(resp.results[1].id === "doc4");
+
+    // test filtering on docids
+    //
+
+    options = {
+        headers: {"Content-Type": "application/json"},
+        body: JSON.stringify({"doc_ids": ["something", "anotherthing", "andmore"]})     
   
+    };
+
+    var req = CouchDB.request("POST", "/test_suite_db/_changes", options);
+    var resp = JSON.parse(req.responseText);
+    T(resp.results.length === 0);
+
+    T(db.save({"_id":"something", "bop" : "plankton"}).ok);
+    var req = CouchDB.request("POST", "/test_suite_db/_changes", options);
+    var resp = JSON.parse(req.responseText);
+    T(resp.results.length === 1);
+    T(resp.results[0].id === "something");
+
+    T(db.save({"_id":"anotherthing", "bop" : "plankton"}).ok);
+    var req = CouchDB.request("POST", "/test_suite_db/_changes", options);
+    var resp = JSON.parse(req.responseText);
+    T(resp.results.length === 2);
+    T(resp.results[0].id === "something");
+    T(resp.results[1].id === "anotherthing");
+
+
+    if (!is_safari && xhr) {
+        // filter docids with continuous
+        xhr = CouchDB.newXhr();
+        xhr.open("POST", "/test_suite_db/_changes?feed=continuous&timeout=500&since=7",
true);
+        xhr.setRequestHeader("Content-Type", "application/json");
+        
+        xhr.send(options.body);
+        
+        T(db.save({"_id":"andmore", "bop" : "plankton"}).ok);
+
+        
+        waitForSuccess(function() {
+            if (xhr.readyState != 4) {
+              throw("still waiting");
+            }
+           console.log(xhr.readyState);
+        }, "andmore-only");
+
+        line = JSON.parse(xhr.responseText.split("\n")[0]);
+        console.log(line);
+        T(line.seq == 8);
+        T(line.id == "andmore");
+    }
+    
   });
 
 };

Modified: couchdb/branches/new_replicator/src/couchdb/couch_changes.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_changes.erl?rev=1040478&r1=1040477&r2=1040478&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_changes.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_changes.erl Tue Nov 30 12:17:09 2010
@@ -82,6 +82,21 @@ get_callback_acc(Callback) when is_funct
     {fun(Ev, Data, _) -> Callback(Ev, Data) end, ok}.
 
 %% @type Req -> #httpd{} | {json_req, JsonObj()}
+make_filter_fun({docids, Docids}, Style, _Req, _Db) ->
+    fun(#doc_info{id=DocId, revs=[#rev_info{rev=Rev}|_]=Revs}) ->
+        case lists:member(DocId, Docids) of
+        true ->
+            case Style of
+            main_only ->
+                [{[{<<"rev">>, couch_doc:rev_to_str(Rev)}]}];
+            all_docs ->
+                [{[{<<"rev">>, couch_doc:rev_to_str(R)}]}
+                        || #rev_info{rev=R} <- Revs]
+            end;
+        _ -> []
+        end
+    end;
+
 make_filter_fun(FilterName, Style, Req, Db) ->
     case [list_to_binary(couch_httpd:unquote(Part))
             || Part <- string:tokens(FilterName, "/")] of

Modified: couchdb/branches/new_replicator/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_httpd_db.erl?rev=1040478&r1=1040477&r2=1040478&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_httpd_db.erl Tue Nov 30 12:17:09 2010
@@ -56,6 +56,25 @@ handle_request(#httpd{path_parts=[DbName
     end.
 
 handle_changes_req(#httpd{method='GET'}=Req, Db) ->
+    handle_changes_req1(Req, Db, nil);
+
+handle_changes_req(#httpd{method='POST'}=Req, Db) ->
+    couch_httpd:validate_ctype(Req, "application/json"),
+    {Props} = couch_httpd:json_body_obj(Req),
+    case couch_util:get_value(<<"doc_ids">>, Props, nil) of
+    nil ->
+        handle_changes_req1(Req, Db, nil);
+    Docids when is_list(Docids) ->
+        handle_changes_req1(Req, Db, Docids);
+    _ ->
+        throw({bad_request, "`docids` member must be a array."}) 
+    end;
+
+handle_changes_req(#httpd{path_parts=[_,<<"_changes">>]}=Req, _Db) ->
+    send_method_not_allowed(Req, "GET,HEAD,POST").
+
+
+handle_changes_req1(Req, Db, Docids) ->
     MakeCallback = fun(Resp) ->
         fun({change, Change, _}, "continuous") ->
             send_chunk(Resp, [?JSON_ENCODE(Change) | "\n"]);
@@ -82,8 +101,13 @@ handle_changes_req(#httpd{method='GET'}=
         end
     end,
     ChangesArgs = parse_changes_query(Req),
-    ChangesFun = couch_changes:handle_changes(ChangesArgs, Req, Db),
-    WrapperFun = case ChangesArgs#changes_args.feed of
+    ChangesArgs1 = case Docids of
+        nil -> ChangesArgs;
+        _ -> ChangesArgs#changes_args{filter={docids, Docids}}
+    end,
+
+    ChangesFun = couch_changes:handle_changes(ChangesArgs1, Req, Db),
+    WrapperFun = case ChangesArgs1#changes_args.feed of
     "normal" ->
         {ok, Info} = couch_db:get_db_info(Db),
         CurrentEtag = couch_httpd:make_etag(Info),
@@ -108,9 +132,6 @@ handle_changes_req(#httpd{method='GET'}=
     end,
     WrapperFun(ChangesFun);
 
-handle_changes_req(#httpd{path_parts=[_,<<"_changes">>]}=Req, _Db) ->
-    send_method_not_allowed(Req, "GET,HEAD").
-
 handle_compact_req(#httpd{method='POST',path_parts=[DbName,_,Id|_]}=Req, _Db) ->
     ok = couch_view_compactor:start_compact(DbName, Id),
     send_json(Req, 202, {[{ok, true}]});



Mime
View raw message