summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2019-09-05 16:03:17 -0400
committerNick Vatamaniuc <vatamane@apache.org>2019-09-05 16:25:12 -0400
commit0b62f85faa59f03ac5d5248477fbf06e38389e3f (patch)
treebbc3fa18ce4f38eb7da3c4fbb8e99335beeb98cd
parentd6b6155f2c0f016c276d7bb2f051b14bfe97201e (diff)
downloadcouchdb-prototype/fdb-layer-fix-update-seq-for-local-docs.tar.gz
Handle update_seq for _local_docsprototype/fdb-layer-fix-update-seq-for-local-docs
On master `_local_docs&update_seq=true` returns the update sequence of the database. Even though it might not make much sense since updating local docs doesn't bump the sequence, it's probably a good idea to stay consistent. It's also worth mentioning another inconsistency is when FDB returns a `total_rows` count for `_local_docs` while master returns `null`. I think that's probably acceptable. Master would return the count if had it available easily and having it seems like a useful thing and an improvement.
-rw-r--r--src/fabric/src/fabric2_db.erl25
-rw-r--r--test/elixir/test/basics_test.exs10
2 files changed, 24 insertions, 11 deletions
diff --git a/src/fabric/src/fabric2_db.erl b/src/fabric/src/fabric2_db.erl
index f3036e4c3..853b5021a 100644
--- a/src/fabric/src/fabric2_db.erl
+++ b/src/fabric/src/fabric2_db.erl
@@ -738,15 +738,7 @@ fold_docs(Db, UserFun, UserAcc0, Options) ->
} = TxDb,
Prefix = erlfdb_tuple:pack({?DB_ALL_DOCS}, DbPrefix),
- NS = couch_util:get_value(namespace, Options),
- DocCount = get_doc_count(TxDb, NS),
- Meta = case lists:keyfind(update_seq, 1, Options) of
- {_, true} ->
- UpdateSeq = fabric2_db:get_update_seq(TxDb),
- [{update_seq, UpdateSeq}];
- _ ->
- []
- end ++ [{total, DocCount}, {offset, null}],
+ Meta = get_all_docs_meta(TxDb, Options),
UserAcc1 = maybe_stop(UserFun({meta, Meta}, UserAcc0)),
@@ -780,8 +772,7 @@ fold_local_docs(Db, UserFun, UserAcc0, Options) ->
} = TxDb,
Prefix = erlfdb_tuple:pack({?DB_LOCAL_DOCS}, DbPrefix),
- DocCount = get_doc_count(TxDb, <<"doc_local_count">>),
- Meta = [{total, DocCount}, {offset, null}],
+ Meta = get_all_docs_meta(TxDb, Options),
UserAcc1 = maybe_stop(UserFun({meta, Meta}, UserAcc0)),
@@ -959,6 +950,18 @@ new_revid(Db, Doc) ->
}.
+get_all_docs_meta(TxDb, Options) ->
+ NS = couch_util:get_value(namespace, Options),
+ DocCount = get_doc_count(TxDb, NS),
+ case lists:keyfind(update_seq, 1, Options) of
+ {_, true} ->
+ UpdateSeq = fabric2_db:get_update_seq(TxDb),
+ [{update_seq, UpdateSeq}];
+ _ ->
+ []
+ end ++ [{total, DocCount}, {offset, null}].
+
+
maybe_set_user_ctx(Db, Options) ->
case fabric2_util:get_value(user_ctx, Options) of
#user_ctx{} = UserCtx ->
diff --git a/test/elixir/test/basics_test.exs b/test/elixir/test/basics_test.exs
index cde11aa5e..d5deaf76b 100644
--- a/test/elixir/test/basics_test.exs
+++ b/test/elixir/test/basics_test.exs
@@ -424,6 +424,11 @@ defmodule BasicsTest do
resp = Couch.get("/#{db_name}/_design_docs?" <> qstr)
assert resp.status_code == 200
assert resp.body == %{"offset" => :null, "rows" => [], "total_rows" => 2}
+
+ # update_seq=true
+ resp = Couch.get("/#{db_name}/_design_docs?update_seq=true")
+ assert resp.status_code == 200
+ assert Map.has_key?(resp.body, "update_seq")
end
@tag :with_db
@@ -480,6 +485,11 @@ defmodule BasicsTest do
resp = Couch.get("/#{db_name}/_local_docs?" <> qstr)
assert resp.status_code == 200
assert resp.body == %{"offset" => :null, "rows" => [], "total_rows" => 2}
+
+ # update_seq=true
+ resp = Couch.get("/#{db_name}/_local_docs?update_seq=true")
+ assert resp.status_code == 200
+ assert Map.has_key?(resp.body, "update_seq")
end
end