|
@@ -13,6 +13,7 @@ import loggerFactory from '~/utils/logger';
|
|
|
import type { PageModel } from '../../models/page';
|
|
import type { PageModel } from '../../models/page';
|
|
|
import { Revision } from '../../models/revision';
|
|
import { Revision } from '../../models/revision';
|
|
|
|
|
|
|
|
|
|
+import { createIndexes } from './create-indexes';
|
|
|
import { createMongoDBPersistence } from './create-mongodb-persistence';
|
|
import { createMongoDBPersistence } from './create-mongodb-persistence';
|
|
|
import { MongodbPersistence } from './extended/mongodb-persistence';
|
|
import { MongodbPersistence } from './extended/mongodb-persistence';
|
|
|
|
|
|
|
@@ -68,7 +69,7 @@ class YjsService implements IYjsService {
|
|
|
ysocketio.initialize();
|
|
ysocketio.initialize();
|
|
|
this.ysocketio = ysocketio;
|
|
this.ysocketio = ysocketio;
|
|
|
|
|
|
|
|
- this.createIndexes();
|
|
|
|
|
|
|
+ createIndexes(MONGODB_PERSISTENCE_COLLECTION_NAME);
|
|
|
|
|
|
|
|
// check accessible page
|
|
// check accessible page
|
|
|
ysocketio.nsp?.use(async(socket, next) => {
|
|
ysocketio.nsp?.use(async(socket, next) => {
|
|
@@ -165,44 +166,6 @@ class YjsService implements IYjsService {
|
|
|
ysocketio['persistence'] = persistece;
|
|
ysocketio['persistence'] = persistece;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private async createIndexes(): Promise<void> {
|
|
|
|
|
-
|
|
|
|
|
- const collection = mongoose.connection.collection(MONGODB_PERSISTENCE_COLLECTION_NAME);
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- await collection.createIndexes([
|
|
|
|
|
- {
|
|
|
|
|
- key: {
|
|
|
|
|
- version: 1,
|
|
|
|
|
- docName: 1,
|
|
|
|
|
- action: 1,
|
|
|
|
|
- clock: 1,
|
|
|
|
|
- part: 1,
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- // for metaKey
|
|
|
|
|
- {
|
|
|
|
|
- key: {
|
|
|
|
|
- version: 1,
|
|
|
|
|
- docName: 1,
|
|
|
|
|
- metaKey: 1,
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- // for flushDocument / clearDocument
|
|
|
|
|
- {
|
|
|
|
|
- key: {
|
|
|
|
|
- docName: 1,
|
|
|
|
|
- clock: 1,
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- ]);
|
|
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
- logger.error('Failed to create Index', err);
|
|
|
|
|
- throw err;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public async getYDocStatus(pageId: string): Promise<YDocStatus> {
|
|
public async getYDocStatus(pageId: string): Promise<YDocStatus> {
|
|
|
const dumpLog = (status: YDocStatus, args?: { [key: string]: number }) => {
|
|
const dumpLog = (status: YDocStatus, args?: { [key: string]: number }) => {
|
|
|
logger.debug(`getYDocStatus('${pageId}') detected '${status}'`, args ?? {});
|
|
logger.debug(`getYDocStatus('${pageId}') detected '${status}'`, args ?? {});
|