Skip to content

Commit

Permalink
perf(repository): prevent multiple array allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaty authored and raymondfeng committed Oct 22, 2018
1 parent b27cc2d commit a026d33
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions packages/repository/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ import * as assert from 'assert';

// tslint:disable:no-any

const nonWhereFields = [
'fields',
'order',
'limit',
'skip',
'offset',
'include',
];

const filterFields = ['where', ...nonWhereFields];

/**
* Operators for where clauses
*/
Expand Down Expand Up @@ -208,15 +219,6 @@ export function isFilter<MT extends object>(
candidate: any,
): candidate is Filter<MT> {
if (typeof candidate !== 'object') return false;
const filterFields = [
'where',
'fields',
'order',
'limit',
'skip',
'offset',
'include',
];
for (const key in candidate) {
if (!filterFields.includes(key)) {
return false;
Expand Down Expand Up @@ -583,14 +585,6 @@ export class FilterBuilder<MT extends object = AnyObject> {
} else {
if (isFilter(constraint)) {
// throw error if imposed Filter has non-where fields
const nonWhereFields = [
'fields',
'order',
'limit',
'skip',
'offset',
'include',
];
for (const key of Object.keys(constraint)) {
if (nonWhereFields.includes(key)) {
throw new Error(
Expand Down

0 comments on commit a026d33

Please sign in to comment.