Skip to content

Commit

Permalink
fix(database): improve performance with entity lookup (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntma committed May 6, 2021
1 parent 7573d2f commit 8b5f104
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/database/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ export default class Database {
model(model: string): typeof Model
model(model: typeof Model | string): typeof Model | string {
const name = typeof model === 'string' ? model : model.entity
const m = this.models()[name]
const entity = this.entities.find((entity) => {
return entity.name === name
})

const m = entity ? entity.model : null

if (!m) {
throw new Error(
Expand All @@ -118,7 +122,11 @@ export default class Database {
baseModel(model: string): typeof Model
baseModel(model: typeof Model | string): typeof Model | string {
const name = typeof model === 'string' ? model : model.entity
const m = this.baseModels()[name]
const entity = this.entities.find((entity) => {
return entity.name === name
})

const m = entity ? this.model(entity.base) : null

if (!m) {
throw new Error(
Expand Down

0 comments on commit 8b5f104

Please sign in to comment.