couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r803358 - in /couchdb/trunk: share/www/script/test/etags_views.js src/couchdb/couch_httpd_db.erl src/couchdb/couch_httpd_show.erl src/couchdb/couch_httpd_view.erl
Date Wed, 12 Aug 2009 03:20:24 GMT
Author: jchris
Date: Wed Aug 12 03:20:21 2009
New Revision: 803358

URL: http://svn.apache.org/viewvc?rev=803358&view=rev
Log:
recloses COUCHDB-4 (view etags) thanks to Matt Goodall for the tests. keep 'em coming!

Modified:
    couchdb/trunk/share/www/script/test/etags_views.js
    couchdb/trunk/src/couchdb/couch_httpd_db.erl
    couchdb/trunk/src/couchdb/couch_httpd_show.erl
    couchdb/trunk/src/couchdb/couch_httpd_view.erl

Modified: couchdb/trunk/share/www/script/test/etags_views.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/etags_views.js?rev=803358&r1=803357&r2=803358&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/etags_views.js (original)
+++ couchdb/trunk/share/www/script/test/etags_views.js Wed Aug 12 03:20:21 2009
@@ -83,4 +83,21 @@
 
   // list etag
   // in the list test for now
+  
+  // A new database should have unique _all_docs etags. 
+  db.deleteDb(); 
+  db.createDb(); 
+  db.save({a: 1}); 
+  xhr = CouchDB.request("GET", "/test_suite_db/_all_docs"); 
+  var etag = xhr.getResponseHeader("etag"); 
+  db.deleteDb(); 
+  db.createDb(); 
+  db.save({a: 2}); 
+  xhr = CouchDB.request("GET", "/test_suite_db/_all_docs"); 
+  var new_etag = xhr.getResponseHeader("etag");
+  T(etag != new_etag);
+  // but still be cacheable
+  xhr = CouchDB.request("GET", "/test_suite_db/_all_docs"); 
+  T(new_etag == xhr.getResponseHeader("etag"));
+  
 };

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=803358&r1=803357&r2=803358&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Wed Aug 12 03:20:21 2009
@@ -406,7 +406,7 @@
     } = QueryArgs = couch_httpd_view:parse_view_params(Req, nil, map),
 
     {ok, Info} = couch_db:get_db_info(Db),
-    CurrentEtag = couch_httpd:make_etag(proplists:get_value(update_seq, Info)),
+    CurrentEtag = couch_httpd:make_etag(Info),
     couch_httpd:etag_respond(Req, CurrentEtag, fun() ->
         TotalRowCount = proplists:get_value(doc_count, Info),
         FoldlFun = couch_httpd_view:make_view_fold_fun(Req, QueryArgs, CurrentEtag, Db,
@@ -521,7 +521,7 @@
         direction = Dir
     } = QueryArgs = couch_httpd_view:parse_view_params(Req, Keys, map),
     {ok, Info} = couch_db:get_db_info(Db),
-    CurrentEtag = couch_httpd:make_etag(proplists:get_value(update_seq, Info)),
+    CurrentEtag = couch_httpd:make_etag(Info),
     couch_httpd:etag_respond(Req, CurrentEtag, fun() ->
 
         TotalRowCount = proplists:get_value(doc_count, Info),

Modified: couchdb/trunk/src/couchdb/couch_httpd_show.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_show.erl?rev=803358&r1=803357&r2=803358&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_show.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_show.erl Wed Aug 12 03:20:21 2009
@@ -164,7 +164,7 @@
     Headers = MReq:get(headers),
     Hlist = mochiweb_headers:to_list(Headers),
     Accept = proplists:get_value('Accept', Hlist),
-    CurrentEtag = couch_httpd_view:view_group_etag(Group, {Lang, ListSrc, Accept, UserCtx}),
+    CurrentEtag = couch_httpd_view:view_group_etag(Group, Db, {Lang, ListSrc, Accept, UserCtx}),
     couch_httpd:etag_respond(Req, CurrentEtag, fun() ->
         % get the os process here
         % pass it into the view fold with closures
@@ -195,7 +195,7 @@
     Headers = MReq:get(headers),
     Hlist = mochiweb_headers:to_list(Headers),
     Accept = proplists:get_value('Accept', Hlist),
-    CurrentEtag = couch_httpd_view:view_group_etag(Group, {Lang, ListSrc, Accept, UserCtx}),
+    CurrentEtag = couch_httpd_view:view_group_etag(Group, Db, {Lang, ListSrc, Accept, UserCtx}),
     couch_httpd:etag_respond(Req, CurrentEtag, fun() ->
         % get the os process here
         % pass it into the view fold with closures
@@ -295,7 +295,7 @@
     Headers = MReq:get(headers),
     Hlist = mochiweb_headers:to_list(Headers),
     Accept = proplists:get_value('Accept', Hlist),
-    CurrentEtag = couch_httpd_view:view_group_etag(Group, {Lang, ListSrc, Accept, UserCtx}),
+    CurrentEtag = couch_httpd_view:view_group_etag(Group, Db, {Lang, ListSrc, Accept, UserCtx}),
     couch_httpd:etag_respond(Req, CurrentEtag, fun() ->
         StartListRespFun = make_reduce_start_resp_fun(QueryServer, Req, Db, CurrentEtag),
         SendListRowFun = make_reduce_send_row_fun(QueryServer, Db),
@@ -328,7 +328,7 @@
     Headers = MReq:get(headers),
     Hlist = mochiweb_headers:to_list(Headers),
     Accept = proplists:get_value('Accept', Hlist),
-    CurrentEtag = couch_httpd_view:view_group_etag(Group, {Lang, ListSrc, Accept, UserCtx,
Keys}),
+    CurrentEtag = couch_httpd_view:view_group_etag(Group, Db, {Lang, ListSrc, Accept, UserCtx,
Keys}),
 
     couch_httpd:etag_respond(Req, CurrentEtag, fun() ->
         StartListRespFun = make_reduce_start_resp_fun(QueryServer, Req, Db, CurrentEtag),

Modified: couchdb/trunk/src/couchdb/couch_httpd_view.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_view.erl?rev=803358&r1=803357&r2=803358&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_view.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_view.erl Wed Aug 12 03:20:21 2009
@@ -17,7 +17,7 @@
 
 -export([get_stale_type/1, get_reduce_type/1, parse_view_params/3]).
 -export([make_view_fold_fun/6, finish_view_fold/3, view_row_obj/3]).
--export([view_group_etag/1, view_group_etag/2, make_reduce_fold_funs/5]).
+-export([view_group_etag/2, view_group_etag/3, make_reduce_fold_funs/5]).
 -export([design_doc_view/5, parse_bool_param/1]).
 
 -import(couch_httpd,
@@ -43,7 +43,7 @@
                 output_map_view(Req, MapView, Group, Db, QueryArgs, Keys);
             _ ->
                 QueryArgs = parse_view_params(Req, Keys, reduce),
-                output_reduce_view(Req, ReduceView, Group, QueryArgs, Keys)
+                output_reduce_view(Req, Db, ReduceView, Group, QueryArgs, Keys)
             end;
         _ ->
             throw({not_found, Reason})
@@ -133,7 +133,7 @@
         QueryArgs = parse_view_params(Req, Keys, reduce),
         {ok, View, Group} = couch_view:get_temp_reduce_view(Db, Language,
             DesignOptions, MapSrc, RedSrc),
-        output_reduce_view(Req, View, Group, QueryArgs, Keys)
+        output_reduce_view(Req, Db, View, Group, QueryArgs, Keys)
     end;
 
 handle_temp_view_req(Req, _Db) ->
@@ -147,7 +147,7 @@
         start_key = StartKey,
         start_docid = StartDocId
     } = QueryArgs,
-    CurrentEtag = view_group_etag(Group),
+    CurrentEtag = view_group_etag(Group, Db),
     couch_httpd:etag_respond(Req, CurrentEtag, fun() ->
         {ok, RowCount} = couch_view:get_row_count(View),
         Start = {StartKey, StartDocId},
@@ -164,7 +164,7 @@
         skip = SkipCount,
         start_docid = StartDocId
     } = QueryArgs,
-    CurrentEtag = view_group_etag(Group, Keys),
+    CurrentEtag = view_group_etag(Group, Db, Keys),
     couch_httpd:etag_respond(Req, CurrentEtag, fun() ->
         {ok, RowCount} = couch_view:get_row_count(View),
         FoldAccInit = {Limit, SkipCount, undefined, [], nil},
@@ -184,7 +184,7 @@
         finish_view_fold(Req, RowCount, FoldResult)
     end).
 
-output_reduce_view(Req, View, Group, QueryArgs, nil) ->
+output_reduce_view(Req, Db, View, Group, QueryArgs, nil) ->
     #view_query_args{
         start_key = StartKey,
         end_key = EndKey,
@@ -195,7 +195,7 @@
         end_docid = EndDocId,
         group_level = GroupLevel
     } = QueryArgs,
-    CurrentEtag = view_group_etag(Group),
+    CurrentEtag = view_group_etag(Group, Db),
     couch_httpd:etag_respond(Req, CurrentEtag, fun() ->
         {ok, GroupRowsFun, RespFun} = make_reduce_fold_funs(Req, GroupLevel, QueryArgs, CurrentEtag,
#reduce_fold_helper_funs{}),
         FoldAccInit = {Limit, Skip, undefined, []},
@@ -204,7 +204,7 @@
         finish_reduce_fold(Req, Resp)
     end);
 
-output_reduce_view(Req, View, Group, QueryArgs, Keys) ->
+output_reduce_view(Req, Db, View, Group, QueryArgs, Keys) ->
     #view_query_args{
         limit = Limit,
         skip = Skip,
@@ -213,7 +213,7 @@
         end_docid = EndDocId,
         group_level = GroupLevel
     } = QueryArgs,
-    CurrentEtag = view_group_etag(Group),
+    CurrentEtag = view_group_etag(Group, Db),
     couch_httpd:etag_respond(Req, CurrentEtag, fun() ->
         {ok, GroupRowsFun, RespFun} = make_reduce_fold_funs(Req, GroupLevel, QueryArgs, CurrentEtag,
#reduce_fold_helper_funs{}),
         {Resp, _RedAcc3} = lists:foldl(
@@ -608,10 +608,11 @@
     send_chunk(Resp, RowFront ++ ?JSON_ENCODE({[{key, Key}, {value, Value}]})),
     {ok, ",\r\n"}.
 
-view_group_etag(Group) ->
-    view_group_etag(Group, nil).
+view_group_etag(Group, Db) ->
+    view_group_etag(Group, Db, nil).
 
-view_group_etag(#group{sig=Sig,current_seq=CurrentSeq}, Extra) ->
+view_group_etag(#group{sig=Sig,current_seq=CurrentSeq}, Db, Extra) ->
+    % ?LOG_ERROR("Group ~p",[Group]),
     % This is not as granular as it could be.
     % If there are updates to the db that do not effect the view index,
     % they will change the Etag. For more granular Etags we'd need to keep



Mime
View raw message