Skip to content

Commit

Permalink
refactor(database): slightly reorder create view code to reduce rc
Browse files Browse the repository at this point in the history
  • Loading branch information
kkopanidis committed Jan 26, 2024
1 parent f12bf62 commit 21c70e6
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions modules/database/src/adapters/mongoose-adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,25 @@ export class MongooseAdapter extends DatabaseAdapter<MongooseSchema> {
this,
true,
);
this.views[viewName] = viewModel;
await viewModel.model.createCollection({
viewOn: model.originalSchema.collectionName,
pipeline: EJSON.parse(query.mongoQuery),
});
this.views[viewName] = viewModel;
const foundView = await this.models['Views'].findOne({ name: viewName });
if (isNil(foundView)) {
await this.models['Views'].create({
name: viewName,
originalSchema: modelName,
joinedSchemas: [...new Set(joinedSchemas.concat(modelName))],
query,
});
}
} catch (e: any) {
if (!e.message.includes('Cannot overwrite')) {
throw e;
}
}
const foundView = await this.models['Views'].findOne({ name: viewName });
if (isNil(foundView)) {
await this.models['Views'].create({
name: viewName,
originalSchema: modelName,
joinedSchemas: [...new Set(joinedSchemas.concat(modelName))],
query,
});
}
}

async guaranteeView(viewName: string) {
Expand Down

0 comments on commit 21c70e6

Please sign in to comment.