Skip to content

Commit

Permalink
fix issue store getByField limit could potentially excess config limit (
Browse files Browse the repository at this point in the history
#1529)

* fix issue store getByField limit could potentially excess config limit

* Update packages/node-core/src/indexer/store.service.ts

Co-authored-by: Scott Twiname <[email protected]>

* typo

---------

Co-authored-by: Scott Twiname <[email protected]>
  • Loading branch information
jiqiang90 and stwiname authored Feb 22, 2023
1 parent b4125ed commit aeb93e2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/node-core/src/indexer/store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,10 +694,15 @@ group by
upperFirst(camelCase(indexField.entityName)) === entity && camelCase(indexField.fieldName) === field
) > -1;
assert(indexed, `to query by field ${String(field)}, an index must be created on model ${entity}`);
if (options?.limit && this.config.queryLimit < options?.limit) {
logger.warn(
`store getByField for entity ${entity} with ${options.limit} records exceeds config limit ${this.config.queryLimit}. Will use ${this.config.queryLimit} as the limit.`
);
}
const records = await model.findAll({
where: {[field]: value},
transaction: this.tx,
limit: options?.limit ?? this.config.queryLimit,
limit: options?.limit ? Math.min(options?.limit, this.config.queryLimit) : this.config.queryLimit,
offset: options?.offset,
});
return records.map((record) => record.toJSON() as T);
Expand Down

0 comments on commit aeb93e2

Please sign in to comment.