Skip to content

Remove MultiTabLocalStore #3436

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 3 commits into from
Jul 20, 2020
Merged

Remove MultiTabLocalStore #3436

merged 3 commits into from
Jul 20, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

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

This PR is part of my effort to create a cache-only entry point into Firestore (for getDocFromLocalCache()). My plan is to split up the component providers and extract one that only provides Persistence, SharedClientState and LocalStore . The "WIP end result" is here: #3425. This PR is a version of the first commit in that PR.

To avoid the combinatorial explosion of ComponentProviders, this PR removes MultiTabLocalStore and instead makes all methods in MultiTabLocalStore tree-shakeable.

@changeset-bot
Copy link

changeset-bot bot commented Jul 17, 2020

💥 No Changeset

Latest commit: 08f927a

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

@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt/onelocalstore branch from 41ea951 to a857f59 Compare July 17, 2020 23:16
@@ -202,7 +202,8 @@ export class FirestoreClient {
enableNetwork(): Promise<void> {
this.verifyNotTerminated();
return this.asyncQueue.enqueue(() => {
return this.syncEngine.enableNetwork();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the FirestoreClient -> SyncEngine -> LocalStore -> Persistence indirection for enableNetwork and disableNetwork since I didn't want to come up with non-conflicting global names for the new free-standing functions.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jul 17, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (ee33ebf) Head (47ef519) Diff
    browser 247 kB 246 kB -836 B (-0.3%)
    esm2017 194 kB 193 kB -393 B (-0.2%)
    main 495 kB 494 kB -880 B (-0.2%)
    module 245 kB 244 kB -826 B (-0.3%)
    react-native 194 kB 194 kB -393 B (-0.2%)
  • @firebase/firestore/exp

    Type Base (ee33ebf) Head (47ef519) Diff
    browser ? 187 kB ? (?)
    main 401 kB 534 kB +133 kB (+33.3%)
    react-native ? 187 kB ? (?)
  • @firebase/firestore/lite

    Type Base (ee33ebf) Head (47ef519) Diff
    browser ? 67.9 kB ? (?)
    main 125 kB 520 kB +395 kB (+316.0%)
    react-native ? 67.9 kB ? (?)
  • @firebase/firestore/memory

    Type Base (ee33ebf) Head (47ef519) Diff
    browser 185 kB 185 kB -168 B (-0.1%)
    esm2017 145 kB 145 kB -93 B (-0.1%)
    main 364 kB 364 kB -157 B (-0.0%)
    module 183 kB 183 kB -168 B (-0.1%)
    react-native 145 kB 145 kB -93 B (-0.1%)
  • firebase

    Type Base (ee33ebf) Head (47ef519) Diff
    firebase-firestore.js 285 kB 285 kB -846 B (-0.3%)
    firebase-firestore.memory.js 224 kB 224 kB -170 B (-0.1%)
    firebase.js 820 kB 820 kB -847 B (-0.1%)

Test Logs

const mutationQueueImpl = debugCast(
localStoreImpl.mutationQueue,
IndexedDbMutationQueue // We only support IndexedDb in multi-tab mode.
);
Copy link
Contributor

Choose a reason for hiding this comment

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

This setup is being done in every reworked method, would it be possible to refactor it out into a helper function returning two values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not that pretty since it needs a cast in the method call, but I changed it:

const [localStoreImpl, mutationQueueImpl] = 
    debugCast(localStore, LocalStoreImpl,  (localStoreImpl as LocalStoreImpl).mutationQueue, IndexedDbMutationQueue);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I undid this since this pattern actually uses one more line for each invocation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, what I had in mind was just

const [localStoreImpl, mutationQueueImpl] = foo(localStore);

with the helper function taking care of everything else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add a multiTabLocalStore function that returns LocalStoreImpl, IndexedDbRemoteDocumentCache, IndexedDbMutationQueue and IndexedDbTargetCache. Does that sound good to you?

* Returns the set of documents that have been updated since the last call.
* If this is the first call, returns the set of changes since client
* initialization. Further invocations will return document changes since
* the point of rejection.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clarify what is meant by rejection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to will return document that have changed since the prior call.

async synchronizeLastDocumentChangeReadTime(): Promise<void> {
this.lastDocumentChangeReadTime = await this.persistence.runTransaction(
/**
* Reads the newest document change from persistence and forwards the internal
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: can you clarify where/to what it's being forwarded?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "forward" does not mean "send something along" but rather "move forward". Rewritten.

@schmidt-sebastian schmidt-sebastian merged commit f0de245 into master Jul 20, 2020
@firebase firebase locked and limited conversation to collaborators Aug 20, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/onelocalstore branch November 9, 2020 22:37
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