Skip to content

LocalStore-only queries #3508

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

Merged
merged 17 commits into from
Jul 30, 2020
Merged

LocalStore-only queries #3508

merged 17 commits into from
Jul 30, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Jul 29, 2020

This removes FirestoreClient from the firestore-exp build. FirestoreClient depends on all components in the system, and as such it is not very well geared for a tree-shakeable SDK.

Instead, the firestore-exp SDK now purely relies on Component Providers and splits up offline-only and online use. This allows LocalStore-only queries in getDocFromCache and getDocsFromCache, dropping their size from 220Kb to 130Kb (ish).

Couple things:

  • I moved the component configuration into the main Firestore class, which has some negative size consequences (pulls in AutoId and other things). On the whole, using the SDK without AutoId (needed for SyncEngine/Persistence/doc()) is pretty impossible though and hence I don't think this affects users bundle sizes.
  • I fixed a bug in scripts/build-bundle.ts, which meant I had to regen the scripts/*.js files.

@changeset-bot
Copy link

changeset-bot bot commented Jul 29, 2020

💥 No Changeset

Latest commit: e519317

Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂

If these changes should be published to npm, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jul 29, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (94986e6) Head (e4e53af) Diff
    browser 247 kB 247 kB +331 B (+0.1%)
    esm2017 193 kB 193 kB +121 B (+0.1%)
    main 471 kB 472 kB +454 B (+0.1%)
    module 244 kB 245 kB +309 B (+0.1%)
    react-native 193 kB 193 kB +121 B (+0.1%)
  • @firebase/firestore/exp

    Type Base (94986e6) Head (e4e53af) Diff
    browser 187 kB 187 kB -578 B (-0.3%)
    main 467 kB 465 kB -2.84 kB (-0.6%)
    module 187 kB 187 kB -578 B (-0.3%)
    react-native 187 kB 187 kB -572 B (-0.3%)
  • @firebase/firestore/memory

    Type Base (94986e6) Head (e4e53af) Diff
    browser 185 kB 186 kB +331 B (+0.2%)
    esm2017 145 kB 145 kB +121 B (+0.1%)
    main 347 kB 347 kB +454 B (+0.1%)
    module 183 kB 184 kB +309 B (+0.2%)
    react-native 145 kB 145 kB +121 B (+0.1%)
  • firebase

    Type Base (94986e6) Head (e4e53af) Diff
    firebase-firestore.js 285 kB 286 kB +307 B (+0.1%)
    firebase-firestore.memory.js 226 kB 226 kB +307 B (+0.1%)
    firebase.js 819 kB 819 kB +309 B (+0.0%)

Test Logs

@@ -111,7 +111,6 @@ export class Firestore
* Only ever called once.
*/
protected _terminate(): Promise<void> {
debugAssert(!this._terminated, 'Cannot invoke _terminate() more than once');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work anymore as this is not called from the AsyncQueue (by the overridden method)

const viewSnapshot = await firestoreClient.getDocumentFromLocalCache(
firestoreClient,
return getEventManager(firestore).then(eventManager =>
enqueueReadDocumentViaSnapshotListener(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: why is this instance of firestoreClient.getDocumentFromLocalCache replaced with enqueueReadDocumentViaSnapshotListener, while the one below is replaced by enqueueReadDocumentFromCache?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getDoc, which does a "default" read (from Server first but with the option of reading from cache if offline). The one below is getDocFromCache, which only reads from cache.

verifyNotInitialized(firestoreImpl);
const settings = firestoreImpl._getSettings();

// `_getSettings()` freezes the client settings and prevents further changes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: should this comment be before the call to _getSettings, for consistency with the previous one in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

firestoreImpl._queue,
remoteStore,
persistence,
/* enabled=*/ true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultranit: there is a space after the opening token but not before the closing token -- make this consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) Fixed here and below.

firestore
);
if (onlineComponentProviderPromise) {
logDebug(LOG_TAG, 'Removing OnlineComponentProvider');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: nothing is logged if the promise was not found -- is this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that is ok. We only log when components are initialized and when they are terminated.

@schmidt-sebastian schmidt-sebastian changed the base branch from mrschmidt/smallerdiff to master July 30, 2020 04:49
@schmidt-sebastian schmidt-sebastian merged commit 8a8e60a into master Jul 30, 2020
@firebase firebase locked and limited conversation to collaborators Aug 30, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/fromcache-v2 branch November 9, 2020 22:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants