-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Low-hanging perf improvements in highlighting code #196
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'contexture-elasticsearch': patch | ||
--- | ||
|
||
Low-hanging perf improvements in elasticsearch highlighting |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,16 +95,19 @@ let getFieldSubFields = (field) => | |
/** | ||
* Returns object of all subfields in a schema. | ||
*/ | ||
let getSchemaSubFields = (schema) => | ||
F.reduceIndexed( | ||
(acc, field, path) => | ||
F.mergeOn( | ||
acc, | ||
_.mapKeys((k) => `${path}.${k}`, getFieldSubFields(field)) | ||
), | ||
{}, | ||
schema.fields | ||
) | ||
let getSchemaSubFields = _.memoize( | ||
(schema) => | ||
F.reduceIndexed( | ||
(acc, field, path) => { | ||
let subFields = getFieldSubFields(field) | ||
for (let k in subFields) acc[`${path}.${k}`] = subFields[k] | ||
return acc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mutating the accumulator and then returning it feels kind of silly to me. Why not just use a |
||
}, | ||
{}, | ||
schema.fields | ||
), | ||
_.get('elasticsearch.index') | ||
) | ||
|
||
/** | ||
* Returns object of all group fields and their subfields in a schema. | ||
|
@@ -148,7 +151,7 @@ export let getAllHighlightFields = _.memoize((schema) => { | |
let collectKeysAndValues = (f, coll) => | ||
F.reduceTree()( | ||
(acc, val, key) => | ||
f(val) ? F.push(val, acc) : f(key) ? F.push(key, acc) : acc, | ||
f(val) ? F.pushOn(acc, val) : f(key) ? F.pushOn(acc, key) : acc, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same kind of thing here. Using |
||
[], | ||
coll | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I actually prefer
F.push
here. Mixing non-mutating with mutating in the same flow is kind of awkward for me. If you want to mutate an array withpush
you should just loop over the array and do that.