add the option use_index={no,yes} (yes by default)

If use_index=no even if the view is indexed by sequence, the index won't
be use. Instead it will fold the btree and return the changes each time
the view map function can emit a value. (default behaviour).


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

Branch: refs/heads/1994-merge-rcouch
Commit: f870b4babdc3081bc63d5ce15878ca2e0dd49cc3
Parents: 70409b2
Author: benoitc <[email protected]>
Authored: Fri Feb 7 15:57:25 2014 +0100
Committer: Paul J. Davis <[email protected]>
Committed: Wed Feb 12 21:05:52 2014 -0600

----------------------------------------------------------------------
 src/couch_httpd_changes.erl | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/f870b4ba/src/couch_httpd_changes.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_changes.erl b/src/couch_httpd_changes.erl
index 56ce559..82d9fe0 100644
--- a/src/couch_httpd_changes.erl
+++ b/src/couch_httpd_changes.erl
@@ -118,6 +118,7 @@ handle_changes_req1(Req, #db{name=DbName}=Db) ->
 
 
 handle_changes(ChangesArgs, Req, Db) ->
+
     case ChangesArgs#changes_args.filter of
         "_view" ->
             handle_view_changes(ChangesArgs, Req, Db);
@@ -146,18 +147,26 @@ handle_view_changes(ChangesArgs, Req, Db) ->
     ViewOptions = parse_view_options(Query, []),
 
     {ok, Infos} = couch_mrview:get_info(Db, DDocId),
-    case lists:member(<<"seq_indexed">>,
-                      proplists:get_value(update_options, Infos, [])) of
-        true ->
+    IsIndexed = lists:member(<<"seq_indexed">>,
+                             proplists:get_value(update_options, Infos,
+                                                 [])),
+
+    NoIndex = couch_httpd:qs_value(Req, "use_index", "yes") =:= "no",
+
+    case {IsIndexed, NoIndex} of
+        {true, false} ->
             handle_view_changes(Db, DDocId, VName, ViewOptions, ChangesArgs,
                                 Req);
-        false when ViewOptions /= [] ->
+        {true, true} when ViewOptions /= [] ->
             ?LOG_ERROR("Tried to filter a non sequence indexed view~n",[]),
             throw({bad_request, seqs_not_indexed});
-        false ->
+        {false, _} when ViewOptions /= [] ->
+            ?LOG_ERROR("Tried to filter a non sequence indexed view~n",[]),
+            throw({bad_request, seqs_not_indexed});
+        {_, _} ->
             %% old method we are getting changes using the btree instead
             %% which is not efficient, log it
-            ?LOG_WARN("Get view changes with seq_indexed=false.~n", []),
+            ?LOG_WARN("Filter without using a seq_indexed view.~n", []),
             couch_changes:handle_changes(ChangesArgs, Req, Db)
     end.
 

Reply via email to