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 2025/02/19 04:33:41 UTC
(couchdb) 01/01: Fix atts_since functionality for doc gets
This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a commit to branch fix-atts-since-for-doc-get
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 4441831c222ba92c8bd3d070af2cf20b75ea9206
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Tue Feb 18 23:22:39 2025 -0500
Fix atts_since functionality for doc gets
Previously, atts_since didn't work for doc GETs with `open_revs=[...]`
parameters so we always re-replicated all the attachments bodies on every
update, even if the user just updated the doc without touching the attachment.
Our `_revs_diff` endpoint returns the `possible_ancestors` list (which is what
`atts_since` is), the replicator app passes it along to the source, and even
our node-level couch_db API handles `atts_since`, but we somehow never passed
that parameter to the fabric call in the `chttpd_db`. It's like we ran the
whole marathon, then stumbled and fell right before the finish line.
---
src/chttpd/src/chttpd_db.erl | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index 062e0bf24..b4c141f8c 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -986,18 +986,16 @@ db_doc_req(#httpd{method = 'GET', mochi_req = MochiReq} = Req, Db, DocId) ->
options = Options0,
atts_since = AttsSince
} = parse_doc_query(Req),
- Options = [{user_ctx, Req#httpd.user_ctx} | Options0],
+ Options1 = [{user_ctx, Req#httpd.user_ctx} | Options0],
+ Options2 =
+ case AttsSince of
+ nil -> Options1;
+ _ -> [{atts_since, AttsSince}, attachments | Options1]
+ end,
case Revs of
[] ->
- Options2 =
- if
- AttsSince /= nil ->
- [{atts_since, AttsSince}, attachments | Options];
- true ->
- Options
- end,
Rev =
- case lists:member(latest, Options) of
+ case lists:member(latest, Options2) of
% couch_doc_open will open the winning rev despite of a rev passed
% https://docs.couchdb.org/en/stable/api/document/common.html?highlight=latest#get--db-docid
true -> nil;
@@ -1006,7 +1004,7 @@ db_doc_req(#httpd{method = 'GET', mochi_req = MochiReq} = Req, Db, DocId) ->
Doc = couch_doc_open(Db, DocId, Rev, Options2),
send_doc(Req, Doc, Options2);
_ ->
- case fabric:open_revs(Db, DocId, Revs, Options) of
+ case fabric:open_revs(Db, DocId, Revs, Options2) of
{ok, []} when Revs == all ->
chttpd:send_error(Req, {not_found, missing});
{ok, Results} ->
@@ -1021,7 +1019,7 @@ db_doc_req(#httpd{method = 'GET', mochi_req = MochiReq} = Req, Db, DocId) ->
fun(Result, AccSeparator) ->
case Result of
{ok, Doc} ->
- JsonDoc = couch_doc:to_json_obj(Doc, Options),
+ JsonDoc = couch_doc:to_json_obj(Doc, Options2),
Json = ?JSON_ENCODE({[{ok, JsonDoc}]}),
send_chunk(Resp, AccSeparator ++ Json);
{{not_found, missing}, RevId} ->
@@ -1038,7 +1036,7 @@ db_doc_req(#httpd{method = 'GET', mochi_req = MochiReq} = Req, Db, DocId) ->
send_chunk(Resp, "]"),
end_json_response(Resp);
true ->
- send_docs_multipart(Req, Results, Options)
+ send_docs_multipart(Req, Results, Options2)
end;
{error, Error} ->
chttpd:send_error(Req, Error)