rnewson commented on a change in pull request #3764:
URL: https://github.com/apache/couchdb/pull/3764#discussion_r715668111



##########
File path: src/chttpd/src/chttpd_changes.erl
##########
@@ -604,31 +605,49 @@ keep_sending_changes(Args, Acc0, FirstRound) ->
                 true ->
                     case wait_updated(Timeout, TimeoutFun, UserAcc3) of
                         {updated, UserAcc4} ->
-                            UserCtx = fabric2_db:get_user_ctx(Db),
-                            DbOptions1 = [{user_ctx, UserCtx} | DbOptions],
-                            case fabric2_db:open(fabric2_db:name(Db), 
DbOptions1) of
-                                {ok, Db2} ->
-                                    ?MODULE:keep_sending_changes(
-                                        Args#changes_args{limit = NewLimit},
-                                        ChangesAcc#changes_acc{
-                                            db = Db2,
-                                            user_acc = UserAcc4,
-                                            seq = EndSeq,
-                                            prepend = Prepend2,
-                                            timeout = Timeout,
-                                            timeout_fun = TimeoutFun
-                                        },
-                                        false
-                                    );
-                                _Else ->
-                                    end_sending_changes(Callback, UserAcc3, 
EndSeq)
+                            AccumulatedTime = timer:now_diff(os:timestamp(), 
T0) div 1000,
+                            Max = changes_duration(),
+                            case AccumulatedTime > Max of
+                                true ->
+                                    end_sending_changes(Callback, UserAcc4, 
EndSeq);
+                                false ->
+                                    UserCtx = fabric2_db:get_user_ctx(Db),
+                                    DbOptions1 = [{user_ctx, UserCtx} | 
DbOptions],
+                                    case fabric2_db:open(fabric2_db:name(Db), 
DbOptions1) of
+                                        {ok, Db2} ->
+                                            ?MODULE:keep_sending_changes(
+                                                Args#changes_args{limit = 
NewLimit},
+                                                ChangesAcc#changes_acc{
+                                                    db = Db2,
+                                                    user_acc = UserAcc4,
+                                                    seq = EndSeq,
+                                                    prepend = Prepend2,
+                                                    timeout = Timeout,
+                                                    timeout_fun = TimeoutFun
+                                                },
+                                                false,
+                                                T0
+                                            );
+                                        _Else ->
+                                            end_sending_changes(Callback, 
UserAcc3, EndSeq)
+                                    end
                             end;
                         {stop, UserAcc4} ->
                             end_sending_changes(Callback, UserAcc4, EndSeq)
                     end
             end
     end.
 
+
+changes_duration() ->
+    %% preserving original (3.x) configuration segment;
+    case config:get("fabric", "changes_duration") of
+        undefined ->
+            infinity;

Review comment:
       this is how it works on 3.x. If you want to impose a duration you set a 
numeric value. If you do not want to impose a duration you delete the entry 
(config:delete or `changes_duration =`).




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to