Skip to content

Commit

Permalink
Merge branch 'master' into mila/BloomFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
milaGGL committed Jan 6, 2023
2 parents eaef9da + 1455bfa commit 036849f
Show file tree
Hide file tree
Showing 28 changed files with 1,002 additions and 481 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-ads-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/database": patch
---

Fixed issue where connectDatabaseToEmulator can be called twice during a hot reload
5 changes: 5 additions & 0 deletions .changeset/quick-radios-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/firestore": patch
---

Update canonifyFilter to compute the canonization for flat conjunctions the same as implicit AND queries.
5 changes: 5 additions & 0 deletions .changeset/stupid-swans-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/firestore": patch
---

Fix an issue that stops some performance optimization being applied.
5 changes: 5 additions & 0 deletions .changeset/wild-geckos-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/util': patch
---

Reformat a comment that causes compile errors in some build toolchains.
6 changes: 6 additions & 0 deletions .changeset/young-hornets-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@firebase/util': minor
'firebase': minor
---

Allow users to specify their environment as `node` or `browser` to override Firebase's runtime environment detection and force the SDK to act as if it were in the respective environment.
6 changes: 4 additions & 2 deletions common/api-review/util.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export interface FirebaseDefaults {
config?: Record<string, string>;
// (undocumented)
emulatorHosts?: Record<string, string>;
forceEnvironment?: 'browser' | 'node';
}

// Warning: (ae-missing-release-tag) "FirebaseError" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down Expand Up @@ -221,11 +222,12 @@ export const getDefaultEmulatorHost: (productName: string) => string | undefined
// @public
export const getDefaultEmulatorHostnameAndPort: (productName: string) => [hostname: string, port: number] | undefined;

// @public
export const getDefaults: () => FirebaseDefaults | undefined;

// @public
export const getExperimentalSetting: <T extends ExperimentalKey>(name: T) => FirebaseDefaults[`_${T}`];

// Warning: (ae-missing-release-tag) "getGlobal" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export function getGlobal(): typeof globalThis;

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"eslint-plugin-unused-imports": "2.0.0",
"express": "4.18.2",
"find-free-port": "2.0.0",
"firebase-tools": "11.2.2",
"firebase-tools": "11.19.0",
"glob": "7.2.3",
"http-server": "14.1.1",
"indexeddbshim": "8.0.0",
Expand Down Expand Up @@ -140,7 +140,7 @@
"protractor": "5.4.2",
"request": "2.88.2",
"semver": "7.3.8",
"simple-git": "3.7.1",
"simple-git": "3.15.0",
"sinon": "9.2.4",
"sinon-chai": "3.7.0",
"source-map-loader": "1.1.3",
Expand Down
8 changes: 5 additions & 3 deletions packages/database/src/api/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,11 @@ export function getDatabase(
const db = _getProvider(app, 'database').getImmediate({
identifier: url
}) as Database;
const emulator = getDefaultEmulatorHostnameAndPort('database');
if (emulator) {
connectDatabaseEmulator(db, ...emulator);
if (!db._instanceStarted) {
const emulator = getDefaultEmulatorHostnameAndPort('database');
if (emulator) {
connectDatabaseEmulator(db, ...emulator);
}
}
return db;
}
Expand Down
18 changes: 18 additions & 0 deletions packages/database/test/exp/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ describe('Database@exp Tests', () => {
const db = getDatabase(defaultApp);
expect(db).to.be.ok;
});
it("doesn't try to connect to emulator after database has already started", async () => {
const db = getDatabase(defaultApp);
const r = ref(db, '.info/connected');
const deferred = new Deferred();
onValue(r, snapshot => {
if (snapshot.val()) {
deferred.resolve();
}
});
await deferred.promise;
process.env.__FIREBASE_DEFAULTS__ = JSON.stringify({
emulatorHosts: {
database: 'localhost:9000'
}
});
expect(() => getDatabase(defaultApp)).to.not.throw();
delete process.env.__FIREBASE_DEFAULTS__;
});

it('Can get database with custom URL', () => {
const db = getDatabase(defaultApp, 'http://foo.bar.com');
Expand Down
8 changes: 8 additions & 0 deletions packages/firestore/src/core/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ export function canonifyFilter(filter: Filter): string {
filter.op.toString() +
canonicalId(filter.value)
);
} else if (compositeFilterIsFlatConjunction(filter)) {
// Older SDK versions use an implicit AND operation between their filters.
// In the new SDK versions, the developer may use an explicit AND filter.
// To stay consistent with the old usages, we add a special case to ensure
// the canonical ID for these two are the same. For example:
// `col.whereEquals("a", 1).whereEquals("b", 2)` should have the same
// canonical ID as `col.where(and(equals("a",1), equals("b",2)))`.
return filter.filters.map(filter => canonifyFilter(filter)).join(',');
} else {
// filter instanceof CompositeFilter
const canonicalIdsString = filter.filters
Expand Down
26 changes: 14 additions & 12 deletions packages/firestore/src/lite-api/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,14 @@ export type QueryFilterConstraint =
| QueryCompositeFilterConstraint;

/**
* Creates a {@link QueryCompositeFilterConstraint} that performs a logical OR
* of all the provided {@link QueryFilterConstraint}s.
* Creates a new {@link QueryCompositeFilterConstraint} that is a disjunction of
* the given filter constraints. A disjunction filter includes a document if it
* satisfies any of the given filters.
*
* @param queryConstraints - Optional. The {@link QueryFilterConstraint}s
* for OR operation. These must be created with calls to {@link where},
* {@link or}, or {@link and}.
* @returns The created {@link QueryCompositeFilterConstraint}.
* @param queryConstraints - Optional. The list of
* {@link QueryFilterConstraint}s to perform a disjunction for. These must be
* created with calls to {@link where}, {@link or}, or {@link and}.
* @returns The newly created {@link QueryCompositeFilterConstraint}.
* @internal TODO remove this internal tag with OR Query support in the server
*/
export function or(
Expand All @@ -388,13 +389,14 @@ export function or(
}

/**
* Creates a {@link QueryCompositeFilterConstraint} that performs a logical AND
* of all the provided {@link QueryFilterConstraint}s.
* Creates a new {@link QueryCompositeFilterConstraint} that is a conjunction of
* the given filter constraints. A conjunction filter includes a document if it
* satisfies all of the given filters.
*
* @param queryConstraints - Optional. The {@link QueryFilterConstraint}s
* for AND operation. These must be created with calls to {@link where},
* {@link or}, or {@link and}.
* @returns The created {@link QueryCompositeFilterConstraint}.
* @param queryConstraints - Optional. The list of
* {@link QueryFilterConstraint}s to perform a conjunction for. These must be
* created with calls to {@link where}, {@link or}, or {@link and}.
* @returns The newly created {@link QueryCompositeFilterConstraint}.
* @internal TODO remove this internal tag with OR Query support in the server
*/
export function and(
Expand Down
4 changes: 4 additions & 0 deletions packages/firestore/src/local/local_documents_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ export class LocalDocumentsView {
overlay.mutation.getFieldMask(),
Timestamp.now()
);
} else {
// no overlay exists
// Using EMPTY to indicate there is no overlay for the document.
mutatedFields.set(doc.key, FieldMask.empty());
}
});

Expand Down
6 changes: 4 additions & 2 deletions packages/firestore/src/local/overlayed_document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ export class OverlayedDocument {
readonly overlayedDocument: Document,

/**
* The fields that are locally mutated by patch mutations. If the overlayed
* document is from set or delete mutations, this returns null.
* The fields that are locally mutated by patch mutations.
*
* If the overlayed document is from set or delete mutations, this is `null`.
* If there is no overlay (mutation) for the document, this is an empty `FieldMask`.
*/
readonly mutatedFields: FieldMask | null
) {}
Expand Down
1 change: 1 addition & 0 deletions packages/firestore/src/model/mutation_batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export class MutationBatch {
if (overlay !== null) {
overlays.set(m.key, overlay);
}

if (!mutableDocument.isValidDocument()) {
mutableDocument.convertToNoDocument(SnapshotVersion.min());
}
Expand Down
14 changes: 13 additions & 1 deletion packages/firestore/test/unit/core/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import {
FieldFilter,
Operator
} from '../../../src/core/filter';
import { andFilter, filter, orFilter } from '../../util/helpers';
import { queryToTarget } from '../../../src/core/query';
import { canonifyTarget } from '../../../src/core/target';
import { andFilter, filter, orFilter, query } from '../../util/helpers';

describe('FieldFilter', () => {
it('exposes field filter members', () => {
Expand Down Expand Up @@ -93,4 +95,14 @@ describe('CompositeFilter', () => {
expect(compositeFilterIsFlat(orFilter2)).false;
expect(compositeFilterIsFlatConjunction(orFilter2)).false;
});

it('computes canonical id of flat conjunctions', () => {
const target1 = query('col', a, b, c);

const target2 = query('col', andFilter(a, b, c));

expect(canonifyTarget(queryToTarget(target1))).to.equal(
canonifyTarget(queryToTarget(target2))
);
});
});
Loading

0 comments on commit 036849f

Please sign in to comment.