summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Newson <rnewson@apache.org>2022-10-10 15:43:51 +0100
committerRobert Newson <rnewson@apache.org>2022-10-10 15:53:00 +0100
commitcbf5b17652cb0545188d1412db4f89bdfd438eb8 (patch)
tree11faa11a090bac78301ed83012b8a0d7e0d4fd01
parentf1b2aac82b712301eb69be03dd3dc1e96efb66dd (diff)
downloadcouchdb-introduce-update-param.tar.gz
Introduce update paramintroduce-update-param
-rw-r--r--src/dreyfus/include/dreyfus.hrl2
-rw-r--r--src/dreyfus/src/dreyfus_httpd.erl14
-rw-r--r--src/dreyfus/src/dreyfus_index.erl8
-rw-r--r--src/dreyfus/src/dreyfus_rpc.erl8
-rw-r--r--src/dreyfus/src/dreyfus_util.erl2
5 files changed, 21 insertions, 13 deletions
diff --git a/src/dreyfus/include/dreyfus.hrl b/src/dreyfus/include/dreyfus.hrl
index 7c6a36945..0a5d5d51a 100644
--- a/src/dreyfus/include/dreyfus.hrl
+++ b/src/dreyfus/include/dreyfus.hrl
@@ -34,7 +34,7 @@
q,
partition=nil,
limit=25,
- stale=false,
+ update=true,
include_docs=false,
bookmark=nil,
sort=relevance,
diff --git a/src/dreyfus/src/dreyfus_httpd.erl b/src/dreyfus/src/dreyfus_httpd.erl
index 39d205b95..3571e00be 100644
--- a/src/dreyfus/src/dreyfus_httpd.erl
+++ b/src/dreyfus/src/dreyfus_httpd.erl
@@ -277,8 +277,10 @@ validate_index_query(q, Value, Args) ->
Args#index_query_args{q = Value};
validate_index_query(partition, Value, Args) ->
Args#index_query_args{partition = Value};
-validate_index_query(stale, Value, Args) ->
- Args#index_query_args{stale = Value};
+validate_index_query(stale, false, Args) ->
+ Args#index_query_args{update = true};
+validate_index_query(stale, "ok", Args) ->
+ Args#index_query_args{update = false};
validate_index_query(limit, Value, Args) ->
Args#index_query_args{limit = Value};
validate_index_query(include_docs, Value, Args) ->
@@ -297,6 +299,8 @@ validate_index_query(group_sort, Value, #index_query_args{grouping = Grouping} =
Args#index_query_args{grouping = Grouping#grouping{sort = Value}};
validate_index_query(group_limit, Value, #index_query_args{grouping = Grouping} = Args) ->
Args#index_query_args{grouping = Grouping#grouping{limit = Value}};
+validate_index_query(update, Value, Args) ->
+ Args#index_query_args{update = Value};
validate_index_query(stable, Value, Args) ->
Args#index_query_args{stable = Value};
validate_index_query(counts, Value, Args) ->
@@ -349,6 +353,10 @@ parse_index_param("group_sort", Value) ->
[{group_sort, ?JSON_DECODE(Value)}];
parse_index_param("group_limit", Value) ->
[{group_limit, parse_positive_int_param("group_limit", Value, "max_group_limit", "200")}];
+parse_index_param("update", "lazy") ->
+ [{update, lazy}];
+parse_index_param("update", Value) ->
+ [{update, parse_bool_param("update", Value)}];
parse_index_param("stable", Value) ->
[{stable, parse_bool_param("stable", Value)}];
parse_index_param("include_fields", Value) ->
@@ -396,6 +404,8 @@ parse_json_index_param(<<"group_sort">>, Value) ->
[{group_sort, Value}];
parse_json_index_param(<<"group_limit">>, Value) ->
[{group_limit, parse_positive_int_param("group_limit", Value, "max_group_limit", "200")}];
+parse_json_index_param(<<"update">>, Value) ->
+ [{update, parse_bool_param("update", Value)}];
parse_json_index_param(<<"stable">>, Value) ->
[{stable, parse_bool_param("stable", Value)}];
parse_json_index_param(<<"include_fields">>, Value) ->
diff --git a/src/dreyfus/src/dreyfus_index.erl b/src/dreyfus/src/dreyfus_index.erl
index df3e68f84..8a8be5d80 100644
--- a/src/dreyfus/src/dreyfus_index.erl
+++ b/src/dreyfus/src/dreyfus_index.erl
@@ -365,7 +365,7 @@ args_to_proplist(#index_query_args{} = Args) ->
{'query', Args#index_query_args.q},
{partition, Args#index_query_args.partition},
{limit, Args#index_query_args.limit},
- {refresh, Args#index_query_args.stale =:= false},
+ {refresh, Args#index_query_args.update =:= true},
{'after', Args#index_query_args.bookmark},
{sort, Args#index_query_args.sort},
{include_fields, Args#index_query_args.include_fields},
@@ -383,7 +383,7 @@ args_to_proplist2(#index_query_args{} = Args) ->
[
{'query', Args#index_query_args.q},
{field, Args#index_query_args.grouping#grouping.by},
- {refresh, Args#index_query_args.stale =:= false},
+ {refresh, Args#index_query_args.update =:= true},
{groups, Args#index_query_args.grouping#grouping.groups},
{group_sort, Args#index_query_args.grouping#grouping.sort},
{sort, Args#index_query_args.sort},
@@ -405,7 +405,7 @@ group1_int(Pid, QueryArgs0) ->
QueryArgs = dreyfus_util:upgrade(QueryArgs0),
#index_query_args{
q = Query,
- stale = Stale,
+ update = Update,
grouping = #grouping{
by = GroupBy,
offset = Offset,
@@ -417,7 +417,7 @@ group1_int(Pid, QueryArgs0) ->
Pid,
Query,
GroupBy,
- Stale =:= false,
+ Update,
Sort,
Offset,
Limit
diff --git a/src/dreyfus/src/dreyfus_rpc.erl b/src/dreyfus/src/dreyfus_rpc.erl
index 2ebc5ffe5..537f048c7 100644
--- a/src/dreyfus/src/dreyfus_rpc.erl
+++ b/src/dreyfus/src/dreyfus_rpc.erl
@@ -41,9 +41,9 @@ call(Fun, DbName, DDoc, IndexName, QueryArgs0) ->
check_interactive_mode(),
{ok, Db} = get_or_create_db(DbName, []),
#index_query_args{
- stale = Stale
+ update = Update
} = QueryArgs,
- {_LastSeq, MinSeq} = calculate_seqs(Db, Stale),
+ {_LastSeq, MinSeq} = calculate_seqs(Db, Update),
case dreyfus_index:design_doc_to_index(DDoc, IndexName) of
{ok, Index} ->
case dreyfus_index_manager:get_index(DbName, Index) of
@@ -114,10 +114,10 @@ get_or_create_db(DbName, Options) ->
Else
end.
-calculate_seqs(Db, Stale) ->
+calculate_seqs(Db, Update) ->
LastSeq = couch_db:get_update_seq(Db),
if
- Stale == ok orelse Stale == update_after ->
+ Update == true orelse Update == lazy ->
{LastSeq, 0};
true ->
{LastSeq, LastSeq}
diff --git a/src/dreyfus/src/dreyfus_util.erl b/src/dreyfus/src/dreyfus_util.erl
index 74593fb9a..910033f8c 100644
--- a/src/dreyfus/src/dreyfus_util.erl
+++ b/src/dreyfus/src/dreyfus_util.erl
@@ -50,8 +50,6 @@ get_shards(DbName, #index_query_args{partition = Partition} = Args) ->
get_shards(DbName, Args) ->
get_shards(DbName, upgrade(Args)).
-use_ushards(#index_query_args{stale = ok}) ->
- true;
use_ushards(#index_query_args{stable = true}) ->
true;
use_ushards(#index_query_args{}) ->