Skip to content

Commit ce49a32

Browse files
Only run the provided delayed operation early
1 parent babdcfd commit ce49a32

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

packages/firestore/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Unreleased
2+
- [fixed] Fixed an issue that could cause Firestore to temporarily go
3+
offline when a Window visibility event occurred.
24
- [feature] Added support for calling `FirebaseFiresore.settings` with
35
`{ ignoreUndefinedProperties: true }`. When set, Firestore ignores
46
undefined properties inside objects rather than rejecting the API call.

packages/firestore/src/local/index_free_query_engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export class IndexFreeQueryEngine implements QueryEngine {
196196
if (getLogLevel() <= LogLevel.DEBUG) {
197197
logDebug(
198198
'IndexFreeQueryEngine',
199-
'Using full collection scan to execute query: %s',
199+
'Using full collection scan to execute query:',
200200
query.toString()
201201
);
202202
}

packages/firestore/src/util/async_queue.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -463,23 +463,21 @@ export class AsyncQueue {
463463
}
464464

465465
/**
466-
* For Tests: Runs some or all delayed operations early.
466+
* Runs some or all delayed operations early.
467467
*
468-
* @param lastTimerId Delayed operations up to and including this TimerId will
469-
* be drained. Throws if no such operation exists. Pass TimerId.All to run
470-
* all delayed operations.
468+
* @param timerId Delayed operations to run. Pass TimerId.All to run all
469+
* delayed operations.
471470
* @returns a Promise that resolves once all operations have been run.
472471
*/
473-
runDelayedOperationsEarly(lastTimerId: TimerId): Promise<void> {
472+
runDelayedOperationsEarly(timerId: TimerId): Promise<void> {
474473
// Note that draining may generate more delayed ops, so we do that first.
475474
return this.drain().then(() => {
476475
// Run ops in the same order they'd run if they ran naturally.
477476
this.delayedOperations.sort((a, b) => a.targetTimeMs - b.targetTimeMs);
478477

479478
for (const op of this.delayedOperations) {
480-
op.skipDelay();
481-
if (lastTimerId !== TimerId.All && op.timerId === lastTimerId) {
482-
break;
479+
if (timerId === TimerId.All || op.timerId === timerId) {
480+
op.skipDelay();
483481
}
484482
}
485483

packages/firestore/test/unit/util/async_queue.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as chaiAsPromised from 'chai-as-promised';
2020
import { expect, use } from 'chai';
2121
import { AsyncQueue, TimerId } from '../../../src/util/async_queue';
2222
import { Code } from '../../../src/util/error';
23-
import { getLogLevel, setLogLevel, LogLevel } from '../../../src/util/log';
23+
import { getLogLevel, LogLevel, setLogLevel } from '../../../src/util/log';
2424
import { Deferred, Rejecter, Resolver } from '../../../src/util/promise';
2525
import { fail } from '../../../src/util/assert';
2626
import { IndexedDbTransactionError } from '../../../src/local/simple_db';
@@ -206,7 +206,13 @@ describe('AsyncQueue', () => {
206206
queue.enqueueAndForget(() => doStep(2));
207207

208208
await queue.runDelayedOperationsEarly(timerId3);
209-
expect(completedSteps).to.deep.equal([1, 2, 3, 4]);
209+
expect(completedSteps).to.deep.equal([1, 2, 4]);
210+
211+
await queue.runDelayedOperationsEarly(timerId2);
212+
expect(completedSteps).to.deep.equal([1, 2, 4, 3]);
213+
214+
await queue.runDelayedOperationsEarly(timerId1);
215+
expect(completedSteps).to.deep.equal([1, 2, 4, 3, 5]);
210216
});
211217

212218
it('Retries retryable operations', async () => {

0 commit comments

Comments
 (0)