Skip to content

Tree-Shake RemoteStore Streams #3568

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 6 commits into from
Sep 9, 2020
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
1,070 changes: 199 additions & 871 deletions packages/firestore/exp/dependencies.json

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions packages/firestore/exp/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import {
setOfflineComponentProvider,
setOnlineComponentProvider
} from './components';

import { DEFAULT_HOST, DEFAULT_SSL } from '../../../lite/src/api/components';
import { DatabaseInfo } from '../../../src/core/database_info';
import { AutoId } from '../../../src/util/misc';
Expand Down Expand Up @@ -209,9 +208,14 @@ export function enableIndexedDbPersistence(
// `getOnlineComponentProvider()`
const settings = firestoreImpl._getSettings();

return firestoreImpl._queue.enqueue(() =>
const onlineComponentProvider = new OnlineComponentProvider();
const offlineComponentProvider = new IndexedDbOfflineComponentProvider(
onlineComponentProvider
);

return firestoreImpl._queue.enqueue(async () => {
// TODO(firestoreexp): Add forceOwningTab
setOfflineComponentProvider(
await setOfflineComponentProvider(
firestoreImpl,
{
durable: true,
Expand All @@ -220,9 +224,10 @@ export function enableIndexedDbPersistence(
settings.cacheSizeBytes || LruParams.DEFAULT_CACHE_SIZE_BYTES,
forceOwningTab: false
},
new IndexedDbOfflineComponentProvider()
)
);
offlineComponentProvider
);
await setOnlineComponentProvider(firestoreImpl, onlineComponentProvider);
});
}

export function enableMultiTabIndexedDbPersistence(
Expand Down
6 changes: 0 additions & 6 deletions packages/firestore/lite/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ export class Firestore
removeComponents(this);
return Promise.resolve();
}

// TODO(firestoreexp): `deleteApp()` should call the delete method above,
// but it still calls INTERNAL.delete().
INTERNAL = {
delete: () => this._delete()
};
}

export function initializeFirestore(
Expand Down
47 changes: 20 additions & 27 deletions packages/firestore/src/core/component_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,19 @@ import {
applyPrimaryState,
applyTargetState,
getActiveClients,
handleCredentialChange,
syncEngineHandleCredentialChange,
newSyncEngine,
SyncEngine
SyncEngine,
ensureWriteCallbacks
} from './sync_engine';
import {
fillWritePipeline,
newRemoteStore,
RemoteStore,
remoteStoreApplyPrimaryState,
remoteStoreShutdown
} from '../remote/remote_store';
import {
EventManager,
newEventManager,
eventManagerOnOnlineStateChange,
eventManagerOnWatchChange,
eventManagerOnWatchError
} from './event_manager';
import { EventManager, newEventManager } from './event_manager';
import { AsyncQueue } from '../util/async_queue';
import { DatabaseId, DatabaseInfo } from './database_info';
import { Datastore, newDatastore } from '../remote/datastore';
Expand Down Expand Up @@ -185,9 +181,21 @@ export class IndexedDbOfflineComponentProvider extends MemoryOfflineComponentPro
localStore!: LocalStore;
gcScheduler!: GarbageCollectionScheduler | null;

constructor(
protected readonly onlineComponentProvider: OnlineComponentProvider
) {
super();
}

async initialize(cfg: ComponentConfiguration): Promise<void> {
await super.initialize(cfg);
await synchronizeLastDocumentChangeReadTime(this.localStore);

await this.onlineComponentProvider.initialize(this, cfg);

// Enqueue writes from a previous session
await ensureWriteCallbacks(this.onlineComponentProvider.syncEngine);
await fillWritePipeline(this.onlineComponentProvider.remoteStore);
}

createGarbageCollectionScheduler(
Expand Down Expand Up @@ -246,16 +254,9 @@ export class IndexedDbOfflineComponentProvider extends MemoryOfflineComponentPro
* `synchronizeTabs` will be enabled.
*/
export class MultiTabOfflineComponentProvider extends IndexedDbOfflineComponentProvider {
constructor(
private readonly onlineComponentProvider: OnlineComponentProvider
) {
super();
}

async initialize(cfg: ComponentConfiguration): Promise<void> {
await super.initialize(cfg);

await this.onlineComponentProvider.initialize(this, cfg);
const syncEngine = this.onlineComponentProvider.syncEngine;

if (this.sharedClientState instanceof WebStorageSharedClientState) {
Expand Down Expand Up @@ -342,17 +343,8 @@ export class OnlineComponentProvider {
this.sharedClientState = offlineComponentProvider.sharedClientState;
this.datastore = this.createDatastore(cfg);
this.remoteStore = this.createRemoteStore(cfg);
this.syncEngine = this.createSyncEngine(cfg);
this.eventManager = this.createEventManager(cfg);

this.syncEngine.subscribe({
onWatchChange: eventManagerOnWatchChange.bind(null, this.eventManager),
onWatchError: eventManagerOnWatchError.bind(null, this.eventManager),
onOnlineStateChange: eventManagerOnOnlineStateChange.bind(
null,
this.eventManager
)
});
this.syncEngine = this.createSyncEngine(cfg);

this.sharedClientState.onlineStateHandler = onlineState =>
applyOnlineStateChange(
Expand All @@ -361,7 +353,7 @@ export class OnlineComponentProvider {
OnlineStateSource.SharedClientState
);

this.remoteStore.remoteSyncer.handleCredentialChange = handleCredentialChange.bind(
this.remoteStore.remoteSyncer.handleCredentialChange = syncEngineHandleCredentialChange.bind(
null,
this.syncEngine
);
Expand Down Expand Up @@ -401,6 +393,7 @@ export class OnlineComponentProvider {
return newSyncEngine(
this.localStore,
this.remoteStore,
this.eventManager,
this.sharedClientState,
cfg.initialUser,
cfg.maxConcurrentLimboResolutions,
Expand Down
Loading