Share LocalDeltaConnectionServer between documents (#23146)

In SessionStorageModelLoader
This commit is contained in:
Matt Rakow 2024-11-20 10:11:15 -08:00 коммит произвёл GitHub
Родитель 948fc52e8d
Коммит 8e4df0d886
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 7 добавлений и 28 удалений

Просмотреть файл

@ -17,10 +17,7 @@ import {
LocalResolver,
LocalSessionStorageDbFactory,
} from "@fluidframework/local-driver/internal";
import {
ILocalDeltaConnectionServer,
LocalDeltaConnectionServer,
} from "@fluidframework/server-local-server";
import { LocalDeltaConnectionServer } from "@fluidframework/server-local-server";
import type { IFluidContainer, ContainerSchema } from "fluid-framework";
import { SharedMap } from "fluid-framework/legacy";
@ -28,7 +25,7 @@ import { DiceRollerController } from "../src/controller.js";
import { makeAppView } from "../src/view.js";
// The local server needs to be shared across the Loader instances for collaboration to happen
const localServerMap = new Map<string, ILocalDeltaConnectionServer>();
const localServer = LocalDeltaConnectionServer.create(new LocalSessionStorageDbFactory());
const urlResolver = new LocalResolver();
@ -43,12 +40,6 @@ export async function getSessionStorageContainer(
containerRuntimeFactory: IRuntimeFactory,
createNew: boolean,
): Promise<{ container: IContainer; attach: (() => Promise<void>) | undefined }> {
let localServer = localServerMap.get(containerId);
if (localServer === undefined) {
localServer = LocalDeltaConnectionServer.create(new LocalSessionStorageDbFactory());
localServerMap.set(containerId, localServer);
}
const documentServiceFactory = new LocalDocumentServiceFactory(localServer);
const url = `${window.location.origin}/${containerId}`;

Просмотреть файл

@ -11,10 +11,7 @@ import {
LocalSessionStorageDbFactory,
createLocalResolverCreateNewRequest,
} from "@fluidframework/local-driver/internal";
import {
ILocalDeltaConnectionServer,
LocalDeltaConnectionServer,
} from "@fluidframework/server-local-server";
import { LocalDeltaConnectionServer } from "@fluidframework/server-local-server";
import { v4 as uuid } from "uuid";
import { IDetachedModel, IModelLoader } from "./interfaces.js";
@ -22,16 +19,7 @@ import { ModelLoader } from "./modelLoader.js";
const urlResolver = new LocalResolver();
const deltaConnectionServerMap = new Map<string, ILocalDeltaConnectionServer>();
const getDocumentServiceFactory = (documentId: string) => {
let deltaConnection = deltaConnectionServerMap.get(documentId);
if (deltaConnection === undefined) {
deltaConnection = LocalDeltaConnectionServer.create(new LocalSessionStorageDbFactory());
deltaConnectionServerMap.set(documentId, deltaConnection);
}
return new LocalDocumentServiceFactory(deltaConnection);
};
const localServer = LocalDeltaConnectionServer.create(new LocalSessionStorageDbFactory());
/**
* @internal
@ -50,7 +38,7 @@ export class SessionStorageModelLoader<ModelType> implements IModelLoader<ModelT
const documentId = uuid();
const modelLoader = new ModelLoader<ModelType>({
urlResolver,
documentServiceFactory: getDocumentServiceFactory(documentId),
documentServiceFactory: new LocalDocumentServiceFactory(localServer),
codeLoader: this.codeLoader,
logger: this.logger,
generateCreateNewRequest: () => createLocalResolverCreateNewRequest(documentId),
@ -61,7 +49,7 @@ export class SessionStorageModelLoader<ModelType> implements IModelLoader<ModelT
const documentId = id;
const modelLoader = new ModelLoader<ModelType>({
urlResolver,
documentServiceFactory: getDocumentServiceFactory(documentId),
documentServiceFactory: new LocalDocumentServiceFactory(localServer),
codeLoader: this.codeLoader,
logger: this.logger,
generateCreateNewRequest: () => createLocalResolverCreateNewRequest(documentId),
@ -71,7 +59,7 @@ export class SessionStorageModelLoader<ModelType> implements IModelLoader<ModelT
public async loadExistingPaused(id: string, sequenceNumber: number): Promise<ModelType> {
const modelLoader = new ModelLoader<ModelType>({
urlResolver,
documentServiceFactory: getDocumentServiceFactory(id),
documentServiceFactory: new LocalDocumentServiceFactory(localServer),
codeLoader: this.codeLoader,
generateCreateNewRequest: () => createLocalResolverCreateNewRequest(id),
});