couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bbast...@apache.org
Subject [08/41] couch-mrview commit: updated refs/heads/master to 28e51f3
Date Fri, 31 Oct 2014 19:53:23 GMT
add supports of view changes in the _changes API

Now when the option `seq_indexed=true` is set in the design doc, the
view filter in _changes will use it to retrieve the results. Compared to
the current way, using a view index will be faster to retrieve changes.
It also gives the possibility to filter changes by key or get changes in
a key range. All the view options can be used.

Note 1: if someone is trying to filter a changes with view options when
the views are not indexed by sequence, a 400 error will be returned.
Note 2: The changes will only be returned when the view is updated if
seq_indexed=true

Conflicts:
	src/couch_mrview_http.erl


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

Branch: refs/heads/master
Commit: dfe991f0fcfe15740c0927c6be3cd9504114b894
Parents: 1c24c42
Author: benoitc <bchesneau@gmail.com>
Authored: Fri Feb 7 15:38:34 2014 +0100
Committer: Benjamin Bastian <benjamin.bastian@gmail.com>
Committed: Thu Oct 30 13:38:33 2014 -0700

----------------------------------------------------------------------
 src/couch_mrview_changes.erl |  6 ++----
 src/couch_mrview_http.erl    |  8 ++++++--
 src/couch_mrview_index.erl   | 20 +++++++++++++++++---
 test/09-index-events.t       | 21 +++++++++++++++++----
 4 files changed, 42 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/dfe991f0/src/couch_mrview_changes.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_changes.erl b/src/couch_mrview_changes.erl
index 2b8f910..a0e5281 100644
--- a/src/couch_mrview_changes.erl
+++ b/src/couch_mrview_changes.erl
@@ -141,10 +141,8 @@ view_changes_since(#vst{dbname=DbName, ddoc=DDocId, view=View,
                 true -> OldSeq
             end,
 
-            case Callback(KV, Acc2) of
-                {ok, Acc3} -> {ok, {Go, Acc3, LastSeq}};
-                {stop, Acc3} -> {stop, {stop, Acc3, LastSeq}}
-            end
+            {Go, Acc3} = Callback(KV, Acc2),
+            {Go, {Go, Acc3, LastSeq}}
     end,
 
     Acc0 = {ok, UserAcc, Since},

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/dfe991f0/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index aeaca8e..f3d3286 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -34,6 +34,10 @@
     check_view_etag/3
 ]).
 
+-export([parse_boolean/1,
+         parse_int/1,
+         parse_pos_int/1]).
+
 -include_lib("couch/include/couch_db.hrl").
 -include_lib("couch_mrview/include/couch_mrview.hrl").
 
@@ -438,8 +442,10 @@ parse_boolean(true) ->
     true;
 parse_boolean(false) ->
     false;
+
 parse_boolean(Val) when is_binary(Val) ->
     parse_boolean(?b2l(Val));
+
 parse_boolean(Val) ->
     case string:to_lower(Val) of
     "true" -> true;
@@ -449,7 +455,6 @@ parse_boolean(Val) ->
         throw({query_parse_error, ?l2b(Msg)})
     end.
 
-
 parse_int(Val) when is_integer(Val) ->
     Val;
 parse_int(Val) ->
@@ -461,7 +466,6 @@ parse_int(Val) ->
         throw({query_parse_error, ?l2b(Msg)})
     end.
 
-
 parse_pos_int(Val) ->
     case parse_int(Val) of
     IntVal when IntVal >= 0 ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/dfe991f0/src/couch_mrview_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_index.erl b/src/couch_mrview_index.erl
index 0b9b236..7598f13 100644
--- a/src/couch_mrview_index.erl
+++ b/src/couch_mrview_index.erl
@@ -39,8 +39,10 @@ get(Property, State) ->
             Opts = State#mrst.design_opts,
             IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
             LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
+            SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
             if IncDesign -> [include_design]; true -> [] end
-                ++ if LocalSeq -> [local_seq]; true -> [] end;
+                ++ if LocalSeq -> [local_seq]; true -> [] end
+                ++ if SeqIndexed -> [seq_indexed]; true -> [] end;
         fd ->
             State#mrst.fd;
         language ->
@@ -56,13 +58,24 @@ get(Property, State) ->
                 language = Lang,
                 update_seq = UpdateSeq,
                 purge_seq = PurgeSeq,
-                views = Views
+                views = Views,
+                design_opts = Opts
             } = State,
             {ok, FileSize} = couch_file:bytes(Fd),
             {ok, ExternalSize} = couch_mrview_util:calculate_external_size(IdBtree,
                                                                            LogBtree,
                                                                            Views),
             ActiveSize = ExternalSize + couch_btree:size(Btree),
+
+            IncDesign = couch_util:get_value(<<"include_design">>, Opts, false),
+            LocalSeq = couch_util:get_value(<<"local_seq">>, Opts, false),
+            SeqIndexed = couch_util:get_value(<<"seq_indexed">>, Opts, false),
+            UpdateOptions =
+                if IncDesign -> [<<"include_design">>]; true -> [] end
+                ++ if LocalSeq -> [<<"local_seq">>]; true -> [] end
+                ++ if SeqIndexed -> [<<"seq_indexed">>]; true -> [] end,
+
+
             {ok, [
                 {signature, list_to_binary(couch_index_util:hexsig(Sig))},
                 {language, Lang},
@@ -74,7 +87,8 @@ get(Property, State) ->
                     {external, ExternalSize}
                 ]}},
                 {update_seq, UpdateSeq},
-                {purge_seq, PurgeSeq}
+                {purge_seq, PurgeSeq},
+                {update_options, UpdateOptions}
             ]};
         Other ->
             throw({unknown_index_property, Other})

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/dfe991f0/test/09-index-events.t
----------------------------------------------------------------------
diff --git a/test/09-index-events.t b/test/09-index-events.t
index 1489e4e..6cc1e9c 100644
--- a/test/09-index-events.t
+++ b/test/09-index-events.t
@@ -15,7 +15,7 @@
 % the License.
 
 main(_) ->
-    etap:plan(4),
+    etap:plan(5),
     case (catch test()) of
         ok ->
             etap:end_tests();
@@ -29,11 +29,18 @@ main(_) ->
 test() ->
     test_util:start_couch(),
     {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, changes),
+    test_info(Db),
     test_update_event(Db),
     test_delete_event(Db),
     test_util:stop_couch(),
     ok.
 
+test_info(Db) ->
+    {ok, Info} = couch_mrview:get_info(Db, <<"_design/bar">>),
+    etap:is(getval(update_options, Info), [<<"seq_indexed">>],
+            "update options OK"),
+    ok.
+
 test_update_event(Db) ->
     {ok, Pid} = couch_index_event:start_link(self()),
     etap:ok(is_pid(Pid), "event handler added"),
@@ -47,11 +54,13 @@ test_update_event(Db) ->
     couch_index_event:stop(Pid).
 
 test_delete_event(Db) ->
-     ok = couch_mrview:refresh(Db, <<"_design/bar">>),
+    ok = couch_mrview:refresh(Db, <<"_design/bar">>),
+    timer:sleep(300),
     {ok, Pid} = couch_index_event:start_link(self()),
+    etap:ok(is_pid(Pid), "delete event handler added"),
 
-    etap:ok(is_pid(Pid), "event handler added"),
-    couch_mrview_test_util:delete_db(<<"foo">>),
+
+    catch couch_mrview_test_util:delete_db(<<"foo">>),
     Expect = {index_delete, {<<"foo">>, <<"_design/bar">>,
                              couch_mrview_index}},
     receive
@@ -59,3 +68,7 @@ test_delete_event(Db) ->
             etap:is(Event, Expect, "index delete events OK")
     end,
     couch_index_event:stop(Pid).
+
+getval(Key, PL) ->
+    {value, {Key, Val}} = lists:keysearch(Key, 1, PL),
+    Val.


Mime
View raw message