Skip to content

Commit a026d33

Browse files
Yatyraymondfeng
authored andcommitted
perf(repository): prevent multiple array allocation
1 parent b27cc2d commit a026d33

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

packages/repository/src/query.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ import * as assert from 'assert';
1313

1414
// tslint:disable:no-any
1515

16+
const nonWhereFields = [
17+
'fields',
18+
'order',
19+
'limit',
20+
'skip',
21+
'offset',
22+
'include',
23+
];
24+
25+
const filterFields = ['where', ...nonWhereFields];
26+
1627
/**
1728
* Operators for where clauses
1829
*/
@@ -208,15 +219,6 @@ export function isFilter<MT extends object>(
208219
candidate: any,
209220
): candidate is Filter<MT> {
210221
if (typeof candidate !== 'object') return false;
211-
const filterFields = [
212-
'where',
213-
'fields',
214-
'order',
215-
'limit',
216-
'skip',
217-
'offset',
218-
'include',
219-
];
220222
for (const key in candidate) {
221223
if (!filterFields.includes(key)) {
222224
return false;
@@ -583,14 +585,6 @@ export class FilterBuilder<MT extends object = AnyObject> {
583585
} else {
584586
if (isFilter(constraint)) {
585587
// throw error if imposed Filter has non-where fields
586-
const nonWhereFields = [
587-
'fields',
588-
'order',
589-
'limit',
590-
'skip',
591-
'offset',
592-
'include',
593-
];
594588
for (const key of Object.keys(constraint)) {
595589
if (nonWhereFields.includes(key)) {
596590
throw new Error(

0 commit comments

Comments
 (0)