Skip to content

Commit

Permalink
Bring back some memoization
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Hernandez committed Feb 13, 2024
1 parent 203b3bc commit 2148a37
Showing 1 changed file with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ let getSchemaSubFields = (schema) => {
/**
* Returns object of all group fields and their subfields in a schema.
*/
let getSchemaGroupFields = (schema) => {
let getSchemaGroupFields = _.memoize((schema) => {
let groupFields = _.pick(
_.uniq(
_.flatMap(
Expand All @@ -123,12 +123,12 @@ let getSchemaGroupFields = (schema) => {
...groupFields,
...getSchemaSubFields({ fields: groupFields }),
}
}
})

/*
* Return object of all fields and their subfields that can be highlighted.
*/
export let getAllHighlightFields = (schema) => {
export let getAllHighlightFields = _.memoize((schema) => {
let groupFields = getSchemaGroupFields(schema)

let canHighlightField = (field, path) =>
Expand All @@ -143,7 +143,7 @@ export let getAllHighlightFields = (schema) => {
...schema.fields,
...getSchemaSubFields(schema),
})
}
})

let collectKeysAndValues = (predicate, coll) => {
let acc = []
Expand Down Expand Up @@ -185,19 +185,27 @@ export let getRequestHighlightFields = (schema, node) => {
}
}

let highlightFields = getAllHighlightFields(schema)

// TODO: `highlightOtherMatches` is an undocumented configuration value that we
// are currently using to work around performance issues when highlighting
// fields not included in the node.
if (!node.highlight?.highlightOtherMatches) {
let subFields = getSchemaSubFields({
fields: _.pick(node.include, schema.fields),
})
highlightFields = _.pick(
_.uniq([...node.include, ..._.keys(subFields)]),
highlightFields
)
}

return F.mapValuesIndexed(
(field, path) =>
F.omitBlank({
...(isBlobField(field) && blobConfiguration),
highlight_query: getHighlightQuery(field, path),
}),
// TODO: `highlightOtherMatches` is an undocumented configuration value that we
// are currently using to work around performance issues when highlighting
// fields not included in the node.
getAllHighlightFields(
node.highlight?.highlightOtherMatches
? schema
: { ...schema, fields: _.pick(node.include, schema.fields) }
)
highlightFields
)
}

0 comments on commit 2148a37

Please sign in to comment.