couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From beno...@apache.org
Subject git commit: since=now. Get changes from now. close #COUCHDB-1501
Date Fri, 22 Jun 2012 20:36:57 GMT
Updated Branches:
  refs/heads/master e6706b63c -> 3bbb26127


since=now. Get changes from now. close #COUCHDB-1501


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/3bbb2612
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/3bbb2612
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/3bbb2612

Branch: refs/heads/master
Commit: 3bbb26127787f2acb88e6602c2fd1d1aa8733956
Parents: e6706b6
Author: benoitc <benoitc@apache.org>
Authored: Fri Jun 22 22:33:25 2012 +0200
Committer: benoitc <benoitc@apache.org>
Committed: Fri Jun 22 22:33:25 2012 +0200

----------------------------------------------------------------------
 share/www/script/test/changes.js |   40 +++++++++++++++++++++++++++++---
 src/couchdb/couch_httpd_db.erl   |    9 +++++-
 2 files changed, 43 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/3bbb2612/share/www/script/test/changes.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/changes.js b/share/www/script/test/changes.js
index 91fde7e..33b3af9 100644
--- a/share/www/script/test/changes.js
+++ b/share/www/script/test/changes.js
@@ -210,6 +210,38 @@ couchTests.changes = function(debug) {
     T(lines[3]=='"last_seq":4}');
 
 
+    // test since=now
+    xhr = CouchDB.newXhr();
+
+    xhr.open("GET", "/test_suite_db/_changes?feed=longpoll&since=now", true);
+    xhr.send("");
+
+    var docBarz = {_id:"barzzzz", bar:1};
+    db.save(docBarz);
+
+    var parse_changes_line = function(line) {
+      if (line.charAt(line.length-1) == ",") {
+        var linetrimmed = line.substring(0, line.length-1);
+      } else {
+        var linetrimmed = line;
+      }
+      return JSON.parse(linetrimmed);
+    };
+
+    waitForSuccess(function() {
+      lines = xhr.responseText.split("\n");
+      if (lines[3] != '"last_seq":5}') {
+        throw("still waiting");
+      }
+    }, "change_lines");
+
+    var change = parse_changes_line(lines[1]);
+    T(change.seq == 5);
+    T(change.id == "barzzzz");
+    T(change.changes[0].rev == docBarz._rev);
+    T(lines[3]=='"last_seq":5}');
+
+
   }
 
   // test the filtered changes
@@ -271,10 +303,10 @@ couchTests.changes = function(debug) {
     xhr.open("GET", "/test_suite_db/_changes?feed=longpoll&filter=changes_filter/bop",
false);
     xhr.send("");
     var resp = JSON.parse(xhr.responseText);
-    T(resp.last_seq == 7);
+    T(resp.last_seq == 8);
     // longpoll waits until a matching change before returning
     xhr = CouchDB.newXhr();
-    xhr.open("GET", "/test_suite_db/_changes?feed=longpoll&since=7&filter=changes_filter/bop",
true);
+    xhr.open("GET", "/test_suite_db/_changes?feed=longpoll&since=8&filter=changes_filter/bop",
true);
     xhr.send("");
     db.save({"_id":"falsy", "bop" : ""}); // empty string is falsy
     db.save({"_id":"bingo","bop" : "bingo"});
@@ -283,12 +315,12 @@ couchTests.changes = function(debug) {
       resp = JSON.parse(xhr.responseText);
     }, "longpoll-since");
 
-    T(resp.last_seq == 9);
+    T(resp.last_seq == 10);
     T(resp.results && resp.results.length > 0 && resp.results[0]["id"]
== "bingo", "filter the correct update");
     xhr.abort();
 
     var timeout = 500;
-    var last_seq = 10;
+    var last_seq = 11;
     while (true) {
 
       // filter with continuous

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3bbb2612/src/couchdb/couch_httpd_db.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl
index e9e4109..4b345da 100644
--- a/src/couchdb/couch_httpd_db.erl
+++ b/src/couchdb/couch_httpd_db.erl
@@ -109,7 +109,7 @@ handle_changes_req2(Req, Db) ->
             send_chunk(Resp, "\n")
         end
     end,
-    ChangesArgs = parse_changes_query(Req),
+    ChangesArgs = parse_changes_query(Req, Db),
     ChangesFun = couch_changes:handle_changes(ChangesArgs, Req, Db),
     WrapperFun = case ChangesArgs#changes_args.feed of
     "normal" ->
@@ -1113,13 +1113,18 @@ parse_doc_query(Req) ->
         end
     end, #doc_query_args{}, couch_httpd:qs(Req)).
 
-parse_changes_query(Req) ->
+parse_changes_query(Req, Db) ->
     lists:foldl(fun({Key, Value}, Args) ->
         case {string:to_lower(Key), Value} of
         {"feed", _} ->
             Args#changes_args{feed=Value};
         {"descending", "true"} ->
             Args#changes_args{dir=rev};
+        {"since", "now"} ->
+            UpdateSeq = couch_util:with_db(Db#db.name, fun(WDb) ->
+                                        couch_db:get_update_seq(WDb)
+                                end),
+            Args#changes_args{since=UpdateSeq};
         {"since", _} ->
             Args#changes_args{since=list_to_integer(Value)};
         {"last-event-id", _} ->


Mime
View raw message