-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(perf): huge filtering execution speed improvements (#694)
* feat(perf): huge filtering execution speed improvements The problem was that previous code was parsing the search values at the same time as processing the filtering check and that is totally unnecessary, the search value once provided will never change when comparing to each cell. This PR is rewriting the Filter Service to process the search values only once (before looping through all cells). Parsing Dates are the biggest performance killer because we take dates, that could be in any format, and we parse (convert) them to MomentJS object and that is expensive on 50,000 or more rows (see below for perf logs before/after).
- Loading branch information
1 parent
844e167
commit f93a24d
Showing
42 changed files
with
1,677 additions
and
896 deletions.
There are no files selected for viewing
44 changes: 26 additions & 18 deletions
44
src/app/modules/angular-slickgrid/filter-conditions/__tests__/booleanFilterCondition.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,63 @@ | ||
import { FieldType, FilterConditionOption } from '../../models/index'; | ||
import { booleanFilterCondition } from '../booleanFilterCondition'; | ||
import { executeMappedCondition } from '../executeMappedCondition'; | ||
import { executeBooleanFilterCondition, getFilterParsedBoolean } from '../booleanFilterCondition'; | ||
import { executeFilterConditionTest } from '../filterConditionProcesses'; | ||
|
||
/** will return True in all cases with only 1 exception when the only searchTerm is inversed to the cell value */ | ||
|
||
describe('booleanFilterCondition method', () => { | ||
describe('executeBooleanFilterCondition method', () => { | ||
it('should return True when no cell value is provided, neither search terms', () => { | ||
const searchTerms = undefined; | ||
const options = { dataKey: '', operator: 'EQ', cellValue: '', fieldType: FieldType.boolean } as FilterConditionOption; | ||
const output = booleanFilterCondition(options); | ||
const output = executeBooleanFilterCondition(options, getFilterParsedBoolean(searchTerms)); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return True when any cell value is provided', () => { | ||
const searchTerms = undefined; | ||
const options = { dataKey: '', operator: 'EQ', cellValue: 'foo', fieldType: FieldType.boolean } as FilterConditionOption; | ||
const output = booleanFilterCondition(options); | ||
const output = executeBooleanFilterCondition(options, getFilterParsedBoolean(searchTerms)); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return True when boolean value True is provided as cell value and called from the "executeMappedCondition"', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: 'true', fieldType: FieldType.boolean, searchTerms: ['true'] } as FilterConditionOption; | ||
const output = executeMappedCondition(options); | ||
it('should return True when boolean value True is provided as cell value and called from the "executeFilterConditionTest"', () => { | ||
const searchTerms = ['true']; | ||
const options = { dataKey: '', operator: 'EQ', cellValue: 'true', fieldType: FieldType.boolean, searchTerms } as FilterConditionOption; | ||
const output = executeFilterConditionTest(options, getFilterParsedBoolean(searchTerms)); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return True when boolean value True is provided as cell value', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: 'true', fieldType: FieldType.boolean, searchTerms: ['true'] } as FilterConditionOption; | ||
const output = booleanFilterCondition(options); | ||
const searchTerms = ['true']; | ||
const options = { dataKey: '', operator: 'EQ', cellValue: 'true', fieldType: FieldType.boolean, searchTerms } as FilterConditionOption; | ||
const output = executeBooleanFilterCondition(options, getFilterParsedBoolean(searchTerms)); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return True when boolean value provided is equal to the searchTerms even when it is a string type', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: true, fieldType: FieldType.boolean, searchTerms: ['true'] } as FilterConditionOption; | ||
const output = booleanFilterCondition(options); | ||
const searchTerms = ['true']; | ||
const options = { dataKey: '', operator: 'EQ', cellValue: true, fieldType: FieldType.boolean, searchTerms } as FilterConditionOption; | ||
const output = executeBooleanFilterCondition(options, getFilterParsedBoolean(searchTerms)); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return True when the cell value is equal to at least 1 of the searchTerms', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: true, fieldType: FieldType.boolean, searchTerms: ['true', 'false'] } as FilterConditionOption; | ||
const output = booleanFilterCondition(options); | ||
const searchTerms = ['true', 'false']; | ||
const options = { dataKey: '', operator: 'EQ', cellValue: true, fieldType: FieldType.boolean, searchTerms } as FilterConditionOption; | ||
const output = executeBooleanFilterCondition(options, getFilterParsedBoolean(searchTerms)); | ||
expect(output).toBe(true); | ||
}); | ||
|
||
it('should return False when cell value is inversed to the searchTerm', () => { | ||
const options = { dataKey: '', operator: 'EQ', cellValue: false, fieldType: FieldType.boolean, searchTerms: ['true'] } as FilterConditionOption; | ||
const output = booleanFilterCondition(options); | ||
const searchTerms = ['true']; | ||
const options = { dataKey: '', operator: 'EQ', cellValue: false, fieldType: FieldType.boolean, searchTerms } as FilterConditionOption; | ||
const output = executeBooleanFilterCondition(options, getFilterParsedBoolean(searchTerms)); | ||
expect(output).toBe(false); | ||
}); | ||
|
||
it('should return False even when Operator is Not Equal because condition is always a strict equal check', () => { | ||
const options = { dataKey: '', operator: 'NE', cellValue: false, fieldType: FieldType.boolean, searchTerms: ['true'] } as FilterConditionOption; | ||
const output = booleanFilterCondition(options); | ||
const searchTerms = ['true']; | ||
const options = { dataKey: '', operator: 'NE', cellValue: false, fieldType: FieldType.boolean, searchTerms } as FilterConditionOption; | ||
const output = executeBooleanFilterCondition(options, getFilterParsedBoolean(searchTerms)); | ||
expect(output).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.