Skip to content

Commit

Permalink
fix(database): sequelize populates cache identifier uniqueness (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
kon14 committed Jan 19, 2023
1 parent 39712ca commit a37d388
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,15 @@ export class SequelizeSchema implements SchemaAdapter<ModelCtor<any>> {
for (const document of documents) {
if (this.relations.hasOwnProperty(relationField)) {
const relationSchema = this.relations[relationField];
if (!cache.hasOwnProperty(document[relation])) {
const cacheIdentifier = `${relation}:${document[relationField]}`;
if (!cache.hasOwnProperty(cacheIdentifier)) {
incrementDbQueries();
const schemaModel = this.adapter.getSchemaModel(relationSchema).model;
cache[document[relation]] = await schemaModel.findOne({
_id: document[relation],
cache[cacheIdentifier] = await schemaModel.findOne({
_id: document[relationField],
});
}
document[relationField] = cache[document[relation]];
document[relationField] = cache[cacheIdentifier];
}
}
}
Expand Down

0 comments on commit a37d388

Please sign in to comment.