Skip to content

Commit 318d83f

Browse files
committed
Updated the canonical ID of flat conjunctions to match the canonical ID of old style implicit flat conjunctions.
1 parent d8af08f commit 318d83f

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/firestore/src/core/filter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,14 @@ export function canonifyFilter(filter: Filter): string {
325325
filter.op.toString() +
326326
canonicalId(filter.value)
327327
);
328+
} else if (compositeFilterIsFlatConjunction(filter)) {
329+
// Older SDK versions use an implicit AND operation between their filters.
330+
// In the new SDK versions, the developer may use an explicit AND filter.
331+
// To stay consistent with the old usages, we add a special case to ensure
332+
// the canonical ID for these two are the same. For example:
333+
// `col.whereEquals("a", 1).whereEquals("b", 2)` should have the same
334+
// canonical ID as `col.where(and(equals("a",1), equals("b",2)))`.
335+
return filter.filters.map(filter => canonifyFilter(filter)).join(',');
328336
} else {
329337
// filter instanceof CompositeFilter
330338
const canonicalIdsString = filter.filters

packages/firestore/test/unit/core/filter.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import {
2525
FieldFilter,
2626
Operator
2727
} from '../../../src/core/filter';
28-
import { andFilter, filter, orFilter } from '../../util/helpers';
28+
import { queryToTarget } from '../../../src/core/query';
29+
import { canonifyTarget } from '../../../src/core/target';
30+
import { andFilter, filter, orFilter, query } from '../../util/helpers';
2931

3032
describe('FieldFilter', () => {
3133
it('exposes field filter members', () => {
@@ -93,4 +95,14 @@ describe('CompositeFilter', () => {
9395
expect(compositeFilterIsFlat(orFilter2)).false;
9496
expect(compositeFilterIsFlatConjunction(orFilter2)).false;
9597
});
98+
99+
it('computes canonical id of flat conjunctions', () => {
100+
const target1 = query('col', a, b, c);
101+
102+
const target2 = query('col', andFilter(a, b, c));
103+
104+
expect(canonifyTarget(queryToTarget(target1))).to.equal(
105+
canonifyTarget(queryToTarget(target2))
106+
);
107+
});
96108
});

0 commit comments

Comments
 (0)