You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2022/10/10 14:51:37 UTC

[couchdb] 02/02: Introduce update param

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

rnewson pushed a commit to branch introduce-update-param
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 2ef335deb52edd9e7e5195e191c19b989870064e
Author: Robert Newson <rn...@apache.org>
AuthorDate: Mon Oct 10 15:43:51 2022 +0100

    Introduce update param
---
 src/dreyfus/include/dreyfus.hrl   |  2 +-
 src/dreyfus/src/dreyfus_httpd.erl | 14 ++++++++++++--
 src/dreyfus/src/dreyfus_index.erl |  8 ++++----
 src/dreyfus/src/dreyfus_rpc.erl   |  8 ++++----
 src/dreyfus/src/dreyfus_util.erl  |  2 --
 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{}) ->