couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r733116 - in /couchdb/trunk: share/www/script/couch_tests.js src/couchdb/couch_db_updater.erl src/couchdb/couch_httpd_db.erl src/couchdb/couch_httpd_view.erl
Date Fri, 09 Jan 2009 19:03:23 GMT
Author: jchris
Date: Fri Jan  9 11:03:22 2009
New Revision: 733116

URL: http://svn.apache.org/viewvc?rev=733116&view=rev
Log:
fixed _all_docs view to use the correct PassedEndFun for binary docid sorting

Modified:
    couchdb/trunk/share/www/script/couch_tests.js
    couchdb/trunk/src/couchdb/couch_db_updater.erl
    couchdb/trunk/src/couchdb/couch_httpd_db.erl
    couchdb/trunk/src/couchdb/couch_httpd_view.erl

Modified: couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/couch_tests.js?rev=733116&r1=733115&r2=733116&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/couch_tests.js [utf-8] Fri Jan  9 11:03:22 2009
@@ -216,6 +216,13 @@
     // and on the deleted one, no doc
     T(all_seq.rows[2].value.deleted);
     T(!all_seq.rows[2].doc);
+    
+    // test the all docs collates sanely
+    db.save({_id: "Z", foo: "Z"});
+    db.save({_id: "a", foo: "a"});
+
+    var rows = db.allDocs({startkey: "Z", endkey: "Z"}).rows;
+    T(rows.length == 1);
   },
   
   // Do some edit conflict detection tests
@@ -1166,7 +1173,7 @@
     T(db.bulkSave(makeDocs(1, numDocs + 1)).ok);
 
     // test that the _all_docs view returns correctly with keys
-    var results = db.allDocs({startkey:"_design%2F", endkey:"_design%2FZZZ"});
+    var results = db.allDocs({startkey:"_design", endkey:"_design0"});
     T(results.rows.length == 1);
 
     for (var loop = 0; loop < 2; loop++) {

Modified: couchdb/trunk/src/couchdb/couch_db_updater.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_db_updater.erl?rev=733116&r1=733115&r2=733116&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_db_updater.erl (original)
+++ couchdb/trunk/src/couchdb/couch_db_updater.erl Fri Jan  9 11:03:22 2009
@@ -14,6 +14,7 @@
 -behaviour(gen_server).
 
 -export([btree_by_id_reduce/2,btree_by_seq_reduce/2]).
+-export([less_docid/2]).
 -export([init/1,terminate/2,handle_call/3,handle_cast/2,code_change/3,handle_info/2]).
 
 -include("couch_db.hrl").
@@ -245,6 +246,12 @@
         lists:sublist(tuple_to_list(New), size(Old) + 1, size(New)-size(Old)),
     list_to_tuple(tuple_to_list(Old) ++ NewValuesTail).
 
+% used for doc insertion, also for the PassedEndFun on all_docs view
+less_docid(A, B) when A==B -> false;
+less_docid(nil, _) -> true; % nil - special key sorts before all
+less_docid({}, _) -> false; % {} -> special key sorts after all
+less_docid(A, B) -> A < B.
+
 init_db(DbName, Filepath, Fd, Header0) ->
     case element(2, Header0) of
     ?LATEST_DISK_VERSION -> ok;
@@ -253,12 +260,7 @@
     Header = simple_upgrade_record(Header0, #db_header{}),
     {ok, SummaryStream} = couch_stream:open(Header#db_header.summary_stream_state, Fd),
     ok = couch_stream:set_min_buffer(SummaryStream, 10000),
-    Less =
-        fun(A,B) when A==B -> false;
-        (nil, _) -> true; % nil - special key sorts before all
-        ({}, _) -> false; % {} -> special key sorts after all
-        (A, B) -> A < B
-        end,
+    Less = fun less_docid/2,
             
     {ok, IdBtree} = couch_btree:open(Header#db_header.fulldocinfo_by_id_btree_state, Fd,
         [{split, fun(X) -> btree_by_id_split(X) end},

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=733116&r1=733115&r2=733116&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Fri Jan  9 11:03:22 2009
@@ -268,6 +268,8 @@
     #view_query_args{
         start_key = StartKey,
         start_docid = StartDocId,
+        end_key = EndKey,
+        end_docid = EndDocId,
         limit = Limit,
         skip = SkipCount,
         direction = Dir
@@ -279,10 +281,22 @@
     end,
     FoldAccInit = {Limit, SkipCount, undefined, []},
     
+    PassedEndFun = 
+    case Dir of
+    fwd ->
+        fun(ViewKey, _ViewId) ->
+            couch_db_updater:less_docid(EndKey, ViewKey)
+        end;
+    rev->
+        fun(ViewKey, _ViewId) ->
+            couch_db_updater:less_docid(ViewKey, EndKey)
+        end
+    end,
+    
     case Keys of
     nil ->
         FoldlFun = couch_httpd_view:make_view_fold_fun(Req, QueryArgs, Db,
-            TotalRowCount, fun couch_db:enum_docs_reduce_to_count/1),
+            TotalRowCount, fun couch_db:enum_docs_reduce_to_count/1, PassedEndFun),
         AdapterFun = fun(#full_doc_info{id=Id}=FullDocInfo, Offset, Acc) ->
             case couch_doc:to_doc_info(FullDocInfo) of
             #doc_info{deleted=false, rev=Rev} ->

Modified: couchdb/trunk/src/couchdb/couch_httpd_view.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_view.erl?rev=733116&r1=733115&r2=733116&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_view.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_view.erl Fri Jan  9 11:03:22 2009
@@ -15,7 +15,7 @@
 
 -export([handle_view_req/2,handle_slow_view_req/2]).
 
--export([parse_view_query/1,parse_view_query/2,make_view_fold_fun/5,finish_view_fold/3]).
+-export([parse_view_query/1,parse_view_query/2,make_view_fold_fun/5, make_view_fold_fun/6,finish_view_fold/3]).
 
 -import(couch_httpd,
     [send_json/2,send_json/3,send_json/4,send_method_not_allowed/2,
@@ -361,14 +361,13 @@
     end.
 
 
-make_view_fold_fun(Req, QueryArgs, Db, TotalViewCount, ReduceCountFun) ->
+make_view_fold_fun(Req, QueryArgs, Db,
+    TotalViewCount, ReduceCountFun) ->
     #view_query_args{
         end_key = EndKey,
         end_docid = EndDocId,
-        include_docs = IncludeDocs,
         direction = Dir
     } = QueryArgs,
-
     PassedEndFun =
     case Dir of
     fwd ->
@@ -380,6 +379,12 @@
             couch_view:less_json([ViewKey, ViewId], [EndKey, EndDocId])
         end
     end,
+    make_view_fold_fun(Req, QueryArgs, Db, TotalViewCount, ReduceCountFun, PassedEndFun).
+
+make_view_fold_fun(Req, QueryArgs, Db, TotalViewCount, ReduceCountFun, PassedEndFun) ->
+    #view_query_args{
+        include_docs = IncludeDocs
+    } = QueryArgs,
 
     fun({{Key, DocId}, Value}, OffsetReds,
                       {AccLimit, AccSkip, Resp, AccRevRows}) ->



Mime
View raw message