Skip to content

Commit

Permalink
Merge 8e6bd38 into 55fef6d
Browse files Browse the repository at this point in the history
  • Loading branch information
dconeybe authored Apr 18, 2024
2 parents 55fef6d + 8e6bd38 commit 6394a2e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .changeset/sharp-lizards-sit.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions packages/firestore/src/local/query_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
21 changes: 10 additions & 11 deletions packages/firestore/src/local/simple_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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`.
*
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/firestore/test/unit/local/simple_db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 6394a2e

Please sign in to comment.