Skip to content

Commit f1799d6

Browse files
committed
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.
1 parent c1a539b commit f1799d6

File tree

3 files changed

+628
-18
lines changed

3 files changed

+628
-18
lines changed

src/chttpd/src/chttpd_db.erl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -986,18 +986,16 @@ db_doc_req(#httpd{method = 'GET', mochi_req = MochiReq} = Req, Db, DocId) ->
986986
options = Options0,
987987
atts_since = AttsSince
988988
} = parse_doc_query(Req),
989-
Options = [{user_ctx, Req#httpd.user_ctx} | Options0],
989+
Options1 = [{user_ctx, Req#httpd.user_ctx} | Options0],
990+
Options2 =
991+
case AttsSince of
992+
nil -> Options1;
993+
_ -> [{atts_since, AttsSince}, attachments | Options1]
994+
end,
990995
case Revs of
991996
[] ->
992-
Options2 =
993-
if
994-
AttsSince /= nil ->
995-
[{atts_since, AttsSince}, attachments | Options];
996-
true ->
997-
Options
998-
end,
999997
Rev =
1000-
case lists:member(latest, Options) of
998+
case lists:member(latest, Options2) of
1001999
% couch_doc_open will open the winning rev despite of a rev passed
10021000
% https://docs.couchdb.org/en/stable/api/document/common.html?highlight=latest#get--db-docid
10031001
true -> nil;
@@ -1006,7 +1004,7 @@ db_doc_req(#httpd{method = 'GET', mochi_req = MochiReq} = Req, Db, DocId) ->
10061004
Doc = couch_doc_open(Db, DocId, Rev, Options2),
10071005
send_doc(Req, Doc, Options2);
10081006
_ ->
1009-
case fabric:open_revs(Db, DocId, Revs, Options) of
1007+
case fabric:open_revs(Db, DocId, Revs, Options2) of
10101008
{ok, []} when Revs == all ->
10111009
chttpd:send_error(Req, {not_found, missing});
10121010
{ok, Results} ->
@@ -1021,7 +1019,7 @@ db_doc_req(#httpd{method = 'GET', mochi_req = MochiReq} = Req, Db, DocId) ->
10211019
fun(Result, AccSeparator) ->
10221020
case Result of
10231021
{ok, Doc} ->
1024-
JsonDoc = couch_doc:to_json_obj(Doc, Options),
1022+
JsonDoc = couch_doc:to_json_obj(Doc, Options2),
10251023
Json = ?JSON_ENCODE({[{ok, JsonDoc}]}),
10261024
send_chunk(Resp, AccSeparator ++ Json);
10271025
{{not_found, missing}, RevId} ->
@@ -1038,7 +1036,7 @@ db_doc_req(#httpd{method = 'GET', mochi_req = MochiReq} = Req, Db, DocId) ->
10381036
send_chunk(Resp, "]"),
10391037
end_json_response(Resp);
10401038
true ->
1041-
send_docs_multipart(Req, Results, Options)
1039+
send_docs_multipart(Req, Results, Options2)
10421040
end;
10431041
{error, Error} ->
10441042
chttpd:send_error(Req, Error)

0 commit comments

Comments
 (0)