diff --git a/.changeset/sharp-lizards-sit.md b/.changeset/sharp-lizards-sit.md new file mode 100644 index 00000000000..e623f71da9b --- /dev/null +++ b/.changeset/sharp-lizards-sit.md @@ -0,0 +1,6 @@ +--- +'@firebase/firestore': patch +'firebase': patch +--- + +Reduce code bundle size by 6.5 kB in applications that only use memory persistence (the default persistence mode). This bundle size regression was accidentally introduced in v10.7.2. diff --git a/packages/firestore/src/local/query_engine.ts b/packages/firestore/src/local/query_engine.ts index b3706975b96..15ec61dd978 100644 --- a/packages/firestore/src/local/query_engine.ts +++ b/packages/firestore/src/local/query_engine.ts @@ -49,7 +49,7 @@ import { LocalDocumentsView } from './local_documents_view'; import { PersistencePromise } from './persistence_promise'; import { PersistenceTransaction } from './persistence_transaction'; import { QueryContext } from './query_context'; -import { SimpleDb } from './simple_db'; +import { getAndroidVersion } from './simple_db'; const DEFAULT_INDEX_AUTO_CREATION_MIN_COLLECTION_SIZE = 100; @@ -65,7 +65,7 @@ function getDefaultRelativeIndexReadCostPerDocument(): number { // Googlers can see b/299284287 for details. if (isSafari()) { return 8; - } else if (SimpleDb.getAndroidVersion(getUA()) > 0) { + } else if (getAndroidVersion(getUA()) > 0) { return 6; } else { return 4; diff --git a/packages/firestore/src/local/simple_db.ts b/packages/firestore/src/local/simple_db.ts index 2fc821efd21..e79df248a0f 100644 --- a/packages/firestore/src/local/simple_db.ts +++ b/packages/firestore/src/local/simple_db.ts @@ -201,7 +201,7 @@ export class SimpleDb { const isUnsupportedIOS = 0 < iOSVersion && iOSVersion < 10; // Android browser: Disable for userse running version < 4.5. - const androidVersion = SimpleDb.getAndroidVersion(ua); + const androidVersion = getAndroidVersion(ua); const isUnsupportedAndroid = 0 < androidVersion && androidVersion < 4.5; if ( @@ -246,16 +246,6 @@ export class SimpleDb { return Number(version); } - // visible for testing - /** Parse User Agent to determine Android version. Returns -1 if not found. */ - static getAndroidVersion(ua: string): number { - const androidVersionRegex = ua.match(/Android ([\d.]+)/i); - const version = androidVersionRegex - ? androidVersionRegex[1].split('.').slice(0, 2).join('.') - : '-1'; - return Number(version); - } - /* * Creates a new SimpleDb wrapper for IndexedDb database `name`. * @@ -470,6 +460,15 @@ export class SimpleDb { } } +/** Parse User Agent to determine Android version. Returns -1 if not found. */ +export function getAndroidVersion(ua: string): number { + const androidVersionRegex = ua.match(/Android ([\d.]+)/i); + const version = androidVersionRegex + ? androidVersionRegex[1].split('.').slice(0, 2).join('.') + : '-1'; + return Number(version); +} + /** * A controller for iterating over a key range or index. It allows an iterate * callback to delete the currently-referenced object, or jump to a new key diff --git a/packages/firestore/test/unit/local/simple_db.test.ts b/packages/firestore/test/unit/local/simple_db.test.ts index aff2761b9c3..b2b7ed3f95a 100644 --- a/packages/firestore/test/unit/local/simple_db.test.ts +++ b/packages/firestore/test/unit/local/simple_db.test.ts @@ -22,6 +22,7 @@ import { Context } from 'mocha'; import { dbKeyComparator } from '../../../src/local/indexeddb_remote_document_cache'; import { PersistencePromise } from '../../../src/local/persistence_promise'; import { + getAndroidVersion, SimpleDb, SimpleDbSchemaConverter, SimpleDbStore, @@ -137,7 +138,7 @@ describe('SimpleDb', () => { ' AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'; expect(SimpleDb.getIOSVersion(iPhoneSafariAgent)).to.equal(10.14); expect(SimpleDb.getIOSVersion(iPadSafariAgent)).to.equal(9.0); - expect(SimpleDb.getAndroidVersion(androidAgent)).to.equal(2.2); + expect(getAndroidVersion(androidAgent)).to.equal(2.2); }); it('can get', async () => {