couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [1/2] couchdb-mango git commit: Ignore design docs when using _all_docs
Date Fri, 31 Mar 2017 17:26:41 GMT
Repository: couchdb-mango
Updated Branches:
  refs/heads/master 6660b37d6 -> 312e2c455


Ignore design docs when using _all_docs

This stops design docs from being returns when using the special
all_docs index


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

Branch: refs/heads/master
Commit: a319d9283872c77d1ceea8129829f78dd59a7209
Parents: 6660b37
Author: Garren Smith <garren.smith@gmail.com>
Authored: Wed Mar 22 14:47:31 2017 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Fri Mar 31 19:21:23 2017 +0200

----------------------------------------------------------------------
 src/mango_cursor_view.erl     | 19 ++++++++++++++++++-
 test/02-basic-find-test.py    |  4 ++--
 test/11-ignore-design-docs.py | 39 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/a319d928/src/mango_cursor_view.erl
----------------------------------------------------------------------
diff --git a/src/mango_cursor_view.erl b/src/mango_cursor_view.erl
index 302acd3..2918a2d 100644
--- a/src/mango_cursor_view.erl
+++ b/src/mango_cursor_view.erl
@@ -20,6 +20,7 @@
 
 -export([
     handle_message/2,
+    handle_all_docs_message/2,
     composite_indexes/2,
     choose_best_index/2
 ]).
@@ -85,11 +86,12 @@ execute(#cursor{db = Db, index = Idx} = Cursor0, UserFun, UserAcc) ->
                 include_docs = true
             },
             Args = apply_opts(Cursor#cursor.opts, BaseArgs),
-            CB = fun ?MODULE:handle_message/2,
             {ok, LastCursor} = case mango_idx:def(Idx) of
                 all_docs ->
+                    CB = fun ?MODULE:handle_all_docs_message/2,
                     fabric:all_docs(Db, CB, Cursor, Args);
                 _ ->
+                    CB = fun ?MODULE:handle_message/2,
                     % Normal view
                     DDoc = ddocid(Idx),
                     Name = mango_idx:name(Idx),
@@ -170,6 +172,15 @@ handle_message({error, Reason}, _Cursor) ->
     {error, Reason}.
 
 
+handle_all_docs_message({row, Props}, Cursor) ->
+    case is_design_doc(Props) of
+        true -> {ok, Cursor};
+        false -> handle_message({row, Props}, Cursor)
+    end;
+handle_all_docs_message(Message, Cursor) ->
+    handle_message(Message, Cursor).
+
+
 handle_doc(#cursor{skip = S} = C, _) when S > 0 ->
     {ok, C#cursor{skip = S - 1}};
 handle_doc(#cursor{limit = L} = C, Doc) when L > 0 ->
@@ -254,3 +265,9 @@ doc_member(Db, RowProps, Opts) ->
                     Else
             end
     end.
+
+is_design_doc(RowProps) ->
+    case couch_util:get_value(id, RowProps) of
+        <<"_design/", _/binary>> -> true;
+        _ -> false
+    end.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/a319d928/test/02-basic-find-test.py
----------------------------------------------------------------------
diff --git a/test/02-basic-find-test.py b/test/02-basic-find-test.py
index c7eb348..e634ce9 100644
--- a/test/02-basic-find-test.py
+++ b/test/02-basic-find-test.py
@@ -237,8 +237,8 @@ class BasicFindTests(mango.UserDocsTests):
 
     def test_empty(self):
         docs = self.db.find({})
-        # 15 users and 9 design docs
-        assert len(docs) == 24
+        # 15 users 
+        assert len(docs) == 15
 
     def test_empty_subsel(self):
         docs = self.db.find({

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/a319d928/test/11-ignore-design-docs.py
----------------------------------------------------------------------
diff --git a/test/11-ignore-design-docs.py b/test/11-ignore-design-docs.py
new file mode 100644
index 0000000..ea7165e
--- /dev/null
+++ b/test/11-ignore-design-docs.py
@@ -0,0 +1,39 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+import mango
+import unittest
+
+DOCS = [
+    {
+        "_id": "_design/my-design-doc",
+    },
+    {
+        "_id": "54af50626de419f5109c962f",
+        "user_id": 0,
+        "age": 10,
+        "name": "Jimi"
+    },
+    {
+        "_id": "54af50622071121b25402dc3",
+        "user_id": 1,
+        "age": 11,
+        "name": "Eddie"
+    }
+]
+
+class IgnoreDesignDocsForAllDocsIndexTests(mango.DbPerClass):
+    def test_should_not_return_design_docs(self):
+        self.db.save_docs(DOCS)
+        docs = self.db.find({"_id": {"$gte": None}})
+        assert len(docs) == 2
+


Mime
View raw message