chore: lazy load sub app in share collection (#1569)

This commit is contained in:
ChengLei Shao 2023-03-15 23:20:29 +08:00 committed by GitHub
parent 3cf06be893
commit 2de165c1eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 12 deletions

View File

@ -99,7 +99,7 @@ pgOnly()('collection sync', () => {
const sub1 = await mainApp.appManager.getApplication('sub1'); const sub1 = await mainApp.appManager.getApplication('sub1');
const getSub1MapRecord = async (app) => { const getSubAppMapRecord = async (app) => {
return await app.db.getRepository('applicationPlugins').findOne({ return await app.db.getRepository('applicationPlugins').findOne({
filter: { filter: {
name: 'map', name: 'map',
@ -107,10 +107,10 @@ pgOnly()('collection sync', () => {
}); });
}; };
expect((await getSub1MapRecord(sub1)).get('enabled')).toBeFalsy(); expect((await getSubAppMapRecord(sub1)).get('enabled')).toBeFalsy();
await mainApp.pm.enable('map'); await mainApp.pm.enable('map');
expect((await getSub1MapRecord(sub1)).get('enabled')).toBeTruthy(); expect((await getSubAppMapRecord(sub1)).get('enabled')).toBeTruthy();
await mainApp.db.getRepository('applications').create({ await mainApp.db.getRepository('applications').create({
values: { values: {
@ -119,7 +119,7 @@ pgOnly()('collection sync', () => {
}); });
const sub2 = await mainApp.appManager.getApplication('sub2'); const sub2 = await mainApp.appManager.getApplication('sub2');
expect((await getSub1MapRecord(sub2)).get('enabled')).toBeTruthy(); expect((await getSubAppMapRecord(sub2)).get('enabled')).toBeTruthy();
}); });
it('should not sync roles in sub app', async () => { it('should not sync roles in sub app', async () => {

View File

@ -194,14 +194,6 @@ export class MultiAppShareCollectionPlugin extends Plugin {
return; return;
} }
// 应用加载完之后,需要将子应用全部载入到内存中
this.app.on('afterLoad', async () => {
const subApplications = await this.db.getRepository('applications').find();
for (const subApplication of subApplications) {
await this.app.appManager.getApplication(subApplication.name);
}
});
this.app.on('beforeSubAppInstall', async ({ subApp }) => { this.app.on('beforeSubAppInstall', async ({ subApp }) => {
const subAppPluginsCollection = subApp.db.getCollection('applicationPlugins'); const subAppPluginsCollection = subApp.db.getCollection('applicationPlugins');
const mainAppPluginsCollection = this.app.db.getCollection('applicationPlugins'); const mainAppPluginsCollection = this.app.db.getCollection('applicationPlugins');