[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Firestore failing to return empty results from the local cache #6624

Merged
merged 20 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove unnecessary resumeToken test
  • Loading branch information
milaGGL committed Oct 6, 2022
commit 91f720d3a7765303d9f81bf7243db8c5ff4a0585
2 changes: 1 addition & 1 deletion packages/firestore/src/core/event_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export class QueryListener {
return false;
}

// Raise data from cache if we have any documents or resume token,
// Raise data from cache if we have any documents, have cached results before,
// or we are offline.
return (
dconeybe marked this conversation as resolved.
Show resolved Hide resolved
!snap.docs.isEmpty() ||
Expand Down
89 changes: 45 additions & 44 deletions packages/firestore/test/unit/api/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import {
} from '../../../src';
import { EmulatorAuthCredentialsProvider } from '../../../src/api/credentials';
import { User } from '../../../src/auth/user';
import { encodeBase64 } from '../../../src/platform/base64';
import { ByteString } from '../../../src/util/byte_string';
import {
collectionReference,
documentReference,
Expand Down Expand Up @@ -179,48 +177,51 @@ describe('QuerySnapshot', () => {
querySnapshot('foo', {}, { a: { a: 1 } }, keys('foo/a'), false, true)
)
).to.be.false;
});

it('resume token should not effect querySnapshot equality', () => {
const resumeToken1 = ByteString.fromBase64String(
encodeBase64('ResumeToken1')
);
const resumeToken1Copy = ByteString.fromBase64String(
encodeBase64('ResumeToken1')
);
const resumeToken2 = ByteString.fromBase64String(
encodeBase64('ResumeToken2')
);

const snapshot1 = querySnapshot(
'foo',
{},
{ a: { a: 1 } },
keys(),
false,
false,
resumeToken1
);
const snapshot1Copy = querySnapshot(
'foo',
{},
{ a: { a: 1 } },
keys(),
false,
false,
resumeToken1Copy
);
const snapshot2 = querySnapshot(
'foo',
{},
{ a: { a: 1 } },
keys(),
false,
false,
resumeToken2
);
expect(snapshotEqual(snapshot1, snapshot1Copy)).to.be.true;
expect(snapshotEqual(snapshot1, snapshot2)).to.be.true;
// hasCachedResults should effect querySnapshot equality
dconeybe marked this conversation as resolved.
Show resolved Hide resolved
expect(
snapshotEqual(
querySnapshot(
'foo',
{},
{ a: { a: 1 } },
keys('foo/a'),
false,
false,
true
),
querySnapshot(
'foo',
{},
{ a: { a: 1 } },
keys('foo/a'),
false,
false,
true
)
)
).to.be.true;
expect(
snapshotEqual(
querySnapshot(
'foo',
{},
{ a: { a: 1 } },
keys('foo/a'),
false,
false,
true
),
querySnapshot(
'foo',
{},
{ a: { a: 1 } },
keys('foo/a'),
false,
false,
false
)
)
).to.be.false;
});

it('JSON.stringify() does not throw', () => {
Expand Down
5 changes: 2 additions & 3 deletions packages/firestore/test/util/api_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
import { DocumentKeySet } from '../../src/model/collections';
import { DocumentSet } from '../../src/model/document_set';
import { JsonObject } from '../../src/model/object_value';
import { ByteString } from '../../src/util/byte_string';
import { TEST_PROJECT } from '../unit/local/persistence_test_helpers';

import { doc, key, path as pathFrom } from './helpers';
Expand Down Expand Up @@ -132,7 +131,7 @@ export function querySnapshot(
mutatedKeys: DocumentKeySet,
fromCache: boolean,
syncStateChanged: boolean,
resumeToken?: ByteString
hasCachedResults?: boolean
): QuerySnapshot {
const query: InternalQuery = newQueryForPath(pathFrom(path));
let oldDocuments: DocumentSet = new DocumentSet();
Expand All @@ -155,7 +154,7 @@ export function querySnapshot(
fromCache,
syncStateChanged,
false,
resumeToken !== undefined && resumeToken.approximateByteSize() > 0
hasCachedResults ?? false
);
const db = firestore();
return new QuerySnapshot(
Expand Down