Skip to content

Commit 53ce817

Browse files
committed
send write requests early if the pipeline is full and contains only unsent write requests
1 parent 686c25d commit 53ce817

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

packages/firestore/src/api/experimental_options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export interface ExperimentalOptions {
3838
* _could_ greatly reduce the number of distinct HTTP requests that are used.
3939
*
4040
* The value must be an integer value strictly greater than zero and less than
41-
* or equal to 2000 (2 seconds). A value of `200` is a good starting point to
42-
* minimize write latency yet still enable a some amount of batching.
41+
* or equal to 10000 (10 seconds). A value of `200` is a good starting point
42+
* to minimize write latency yet still enable some amount of batching.
4343
*
4444
* See https://github.com/firebase/firebase-js-sdk/issues/5971 for rationale
4545
* and background information that motivated this option.

packages/firestore/src/lite-api/settings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ const MAX_LONG_POLLING_TIMEOUT_SECONDS = 30;
5555
// Whether long-polling auto-detected is enabled by default.
5656
const DEFAULT_AUTO_DETECT_LONG_POLLING = true;
5757

58-
const MAX_SEND_WRITE_REQUEST_DELAY_MS = 2000;
58+
// Set some maximum value for `sendWriteRequestsDelayMs` to avoid it being set
59+
// to a value so large that it appears that write requests are never being sent.
60+
const MAX_SEND_WRITE_REQUEST_DELAY_MS = 10000;
5961

6062
/**
6163
* Specifies custom configurations for your Cloud Firestore instance.

packages/firestore/src/remote/remote_store.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,14 @@ function addToWritePipeline(
764764
writeRequestSent: false
765765
});
766766

767-
if (remoteStoreImpl.sendWriteRequestsDelayMs === null) {
767+
const writePipelineContainsOnlyUnsentWriteRequests =
768+
remoteStoreImpl.writePipeline.every(entry => !entry.writeRequestSent);
769+
770+
if (
771+
remoteStoreImpl.sendWriteRequestsDelayMs === null ||
772+
(!canAddToWritePipeline(remoteStoreImpl) &&
773+
writePipelineContainsOnlyUnsentWriteRequests)
774+
) {
768775
remoteStoreImpl.sendWriteRequestsOperation?.cancel();
769776
remoteStoreImpl.sendWriteRequestsOperation = null;
770777
sendWriteRequestsFromPipeline(remoteStoreImpl);

0 commit comments

Comments
 (0)