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

Firestore: simple_db.ts: move getAndroidVersion() to a free function #8178

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading