couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject [3/5] couchdb-mango git commit: cleanup
Date Wed, 27 Jan 2016 13:30:24 GMT
cleanup


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

Branch: refs/heads/mango-catch-all
Commit: f2df0b6dfeb57ed1f07851aaa4ddbd5a33d80385
Parents: c0a822f
Author: Robert Kowalski <robertkowalski@apache.org>
Authored: Wed Jan 27 14:08:35 2016 +0100
Committer: Robert Kowalski <robertkowalski@apache.org>
Committed: Wed Jan 27 14:08:35 2016 +0100

----------------------------------------------------------------------
 src/mango_cursor.erl      | 28 +++++-----------------------
 src/mango_cursor_view.erl |  2 ++
 src/mango_httpd.erl       | 25 +++----------------------
 src/mango_util.erl        | 25 ++++++++++++++++++++++++-
 4 files changed, 34 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/f2df0b6d/src/mango_cursor.erl
----------------------------------------------------------------------
diff --git a/src/mango_cursor.erl b/src/mango_cursor.erl
index 5e7053b..9860c31 100644
--- a/src/mango_cursor.erl
+++ b/src/mango_cursor.erl
@@ -31,32 +31,14 @@
 
 create(Db, Selector0, Opts) ->
     Selector = mango_selector:normalize(Selector0),
-
-    ExistingIndexes = mango_idx:list(Db),
-    if ExistingIndexes /= [] -> ok; true ->
-        ?MANGO_ERROR({no_usable_index, no_indexes_defined})
-    end,
-
-    FilteredIndexes = maybe_filter_indexes(ExistingIndexes, Opts),
-    if FilteredIndexes /= [] -> ok; true ->
-        ?MANGO_ERROR({no_usable_index, no_index_matching_name})
-    end,
-
-    SortIndexes = mango_idx:for_sort(FilteredIndexes, Opts),
-    if SortIndexes /= [] -> ok; true ->
-        ?MANGO_ERROR({no_usable_index, missing_sort_index})
-    end,
-
-    UsableFilter = fun(I) -> mango_idx:is_usable(I, Selector) end,
-    UsableIndexes = lists:filter(UsableFilter, SortIndexes),
+    UsableIndexes = mango_util:get_usable_indexes(Db, Selector0, Opts),
+    io:format("UsableIndexes ~p~n", [UsableIndexes]),
 
     case length(UsableIndexes) of
         0 ->
-            % fallback to _id > null for better usability
-            NewSelector = {[{<<"$and">>, [Selector, {[{<<"_id">>,
{[{<<"$gt">>, null}]}}]}]}]},
-            couch_log:warning("no matching index found, create an index to optimize query
time", []),
-            couch_log:warning("~p", [Opts]),
-            create(Db, NewSelector, Opts);
+            AllDocs = mango_idx:special(Db),
+            io:format("UsableIndexesAllDocs ~p~n", [AllDocs]),
+            create_cursor(Db, AllDocs, Selector, Opts);
         _ ->
             create_cursor(Db, UsableIndexes, Selector, Opts)
     end.

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/f2df0b6d/src/mango_cursor_view.erl
----------------------------------------------------------------------
diff --git a/src/mango_cursor_view.erl b/src/mango_cursor_view.erl
index cb35968..1b71ada 100644
--- a/src/mango_cursor_view.erl
+++ b/src/mango_cursor_view.erl
@@ -66,6 +66,7 @@ explain(Cursor) ->
 
 
 execute(#cursor{db = Db, index = Idx} = Cursor0, UserFun, UserAcc) ->
+    io:format("execute cursor index ~p~n", [Idx]),
     Cursor = Cursor0#cursor{
         user_fun = UserFun,
         user_acc = UserAcc
@@ -75,6 +76,7 @@ execute(#cursor{db = Db, index = Idx} = Cursor0, UserFun, UserAcc) ->
             % empty indicates unsatisfiable ranges, so don't perform search
             {ok, UserAcc};
         _ ->
+            io:format("execute cursor index ~p~p~n", [Idx, Cursor#cursor.ranges]),
             BaseArgs = #mrargs{
                 view_type = map,
                 reduce = false,

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/f2df0b6d/src/mango_httpd.erl
----------------------------------------------------------------------
diff --git a/src/mango_httpd.erl b/src/mango_httpd.erl
index ac10d77..eb960cd 100644
--- a/src/mango_httpd.erl
+++ b/src/mango_httpd.erl
@@ -229,30 +229,11 @@ convert_to_design_id(DDocId) ->
 
 
 start_find_resp(Req, Db, Sel, Opts) ->
-    chttpd:start_delayed_json_response(Req, 200, [], maybeAddWarning(Db, Sel, Opts)).
+    chttpd:start_delayed_json_response(Req, 200, [], maybe_add_warning(Db, Sel, Opts)).
 
 
-maybeAddWarning(Db, Selector0, Opts) ->
-    Selector = mango_selector:normalize(Selector0),
-
-    ExistingIndexes = mango_idx:list(Db),
-    if ExistingIndexes /= [] -> ok; true ->
-        ?MANGO_ERROR({no_usable_index, no_indexes_defined})
-    end,
-
-    FilteredIndexes = mango_cursor:maybe_filter_indexes(ExistingIndexes, Opts),
-    if FilteredIndexes /= [] -> ok; true ->
-        ?MANGO_ERROR({no_usable_index, no_index_matching_name})
-    end,
-
-    SortIndexes = mango_idx:for_sort(FilteredIndexes, Opts),
-    if SortIndexes /= [] -> ok; true ->
-        ?MANGO_ERROR({no_usable_index, missing_sort_index})
-    end,
-
-    UsableFilter = fun(I) -> mango_idx:is_usable(I, Selector) end,
-    UsableIndexes = lists:filter(UsableFilter, SortIndexes),
-
+maybe_add_warning(Db, Selector, Opts) ->
+    UsableIndexes = mango_util:get_usable_indexes(Db, Selector, Opts),
     case length(UsableIndexes) of
         0 ->
             "{\"_warning\":\"no matching index found, create an index to optimize query time\",\r\n\"docs\":[";

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/f2df0b6d/src/mango_util.erl
----------------------------------------------------------------------
diff --git a/src/mango_util.erl b/src/mango_util.erl
index c3513dc..5ee5bb0 100644
--- a/src/mango_util.erl
+++ b/src/mango_util.erl
@@ -42,7 +42,9 @@
 
     parse_field/1,
 
-    cached_re/2
+    cached_re/2,
+
+    get_usable_indexes/3
 ]).
 
 
@@ -395,6 +397,27 @@ check_non_empty(Field, Parts) ->
             Parts
     end.
 
+get_usable_indexes(Db, Selector0, Opts) ->
+    Selector = mango_selector:normalize(Selector0),
+
+    ExistingIndexes = mango_idx:list(Db),
+    if ExistingIndexes /= [] -> ok; true ->
+        ?MANGO_ERROR({no_usable_index, no_indexes_defined})
+    end,
+
+    FilteredIndexes = mango_cursor:maybe_filter_indexes(ExistingIndexes, Opts),
+    if FilteredIndexes /= [] -> ok; true ->
+        ?MANGO_ERROR({no_usable_index, no_index_matching_name})
+    end,
+
+    SortIndexes = mango_idx:for_sort(FilteredIndexes, Opts),
+    if SortIndexes /= [] -> ok; true ->
+        ?MANGO_ERROR({no_usable_index, missing_sort_index})
+    end,
+
+    UsableFilter = fun(I) -> mango_idx:is_usable(I, Selector) end,
+    lists:filter(UsableFilter, SortIndexes).
+
 
 -ifdef(TEST).
 -include_lib("eunit/include/eunit.hrl").


Mime
View raw message