You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2023/05/07 20:56:13 UTC

[couchdb] branch main updated: Remove duplicate etag generation function

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/main by this push:
     new 1a59e5d70 Remove duplicate etag generation function
1a59e5d70 is described below

commit 1a59e5d7055d640be10de0ee4a928e5caa696bb8
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Sun May 7 13:08:47 2023 -0400

    Remove duplicate etag generation function
    
    Use the couch_httpd one as it would be odd for couch_httpd to call chttpd.
    
    Also fix the test assertion order: the first argument should be the expected
    value, the second one should be the test value [1]
    
    [1] https://www.erlang.org/doc/apps/eunit/chapter.html#Assert_macros
---
 src/chttpd/src/chttpd.erl                 | 3 +--
 src/couch/src/couch_httpd.erl             | 4 ++--
 src/couch/test/eunit/couch_etag_tests.erl | 4 ++--
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index ee1219511..689af7cef 100644
--- a/src/chttpd/src/chttpd.erl
+++ b/src/chttpd/src/chttpd.erl
@@ -813,8 +813,7 @@ doc_etag(#doc{id = Id, body = Body, revs = {Start, [DiskRev | _]}}) ->
     couch_httpd:doc_etag(Id, Body, {Start, DiskRev}).
 
 make_etag(Term) ->
-    <<SigInt:128/integer>> = exxhash:xxhash128(term_to_binary(Term)),
-    list_to_binary(io_lib:format("\"~.36B\"", [SigInt])).
+    couch_httpd:make_etag(Term).
 
 etag_match(Req, CurrentEtag) when is_binary(CurrentEtag) ->
     etag_match(Req, binary_to_list(CurrentEtag));
diff --git a/src/couch/src/couch_httpd.erl b/src/couch/src/couch_httpd.erl
index 76f8279f6..91c7f91ee 100644
--- a/src/couch/src/couch_httpd.erl
+++ b/src/couch/src/couch_httpd.erl
@@ -745,8 +745,8 @@ rev_etag({Start, DiskRev}) ->
     <<$", Rev/binary, $">>.
 
 make_etag(Term) ->
-    <<SigInt:128/integer>> = couch_hash:md5_hash(term_to_binary(Term)),
-    iolist_to_binary([$", io_lib:format("~.36B", [SigInt]), $"]).
+    <<SigInt:128/integer>> = exxhash:xxhash128(?term_to_bin(Term)),
+    list_to_binary(io_lib:format("\"~.36B\"", [SigInt])).
 
 etag_match(Req, CurrentEtag) when is_binary(CurrentEtag) ->
     etag_match(Req, binary_to_list(CurrentEtag));
diff --git a/src/couch/test/eunit/couch_etag_tests.erl b/src/couch/test/eunit/couch_etag_tests.erl
index 72db6008a..54e677631 100644
--- a/src/couch/test/eunit/couch_etag_tests.erl
+++ b/src/couch/test/eunit/couch_etag_tests.erl
@@ -16,12 +16,12 @@
 
 local_with_empty_body_test() ->
     Etag = couch_httpd:doc_etag(<<"_local/local-and-empty">>, {[]}, {0, <<"1">>}),
-    ?assertEqual(Etag, <<"\"5ZVXQYO7VLEOU0TL9VXDNP5PV\"">>).
+    ?assertEqual(<<"\"A4Q262OE0BOPODSYG6Z2A449\"">>, Etag).
 
 local_with_body_test() ->
     DocBody = {[{<<"hello">>, <<"world">>}, {<<"relax">>, true}]},
     Etag = couch_httpd:doc_etag(<<"_local/local-with-body">>, DocBody, {0, <<"1">>}),
-    ?assertEqual(Etag, <<"\"CEFXP6WH8OKYIWO1GLGBHKCCA\"">>).
+    ?assertEqual(<<"\"266X8HX6TVMBGQBJAGSY0JON\"">>, Etag).
 
 normal_doc_uses_rev_test() ->
     DocBody = {[{<<"hello">>, <<"world">>}, {<<"relax">>, true}]},