Skip to content

Commit

Permalink
fix: slight optimization for query requests
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jan 10, 2024
1 parent 425ab3a commit 706581b
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/components/QueryData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ const userSettingsCategory = (category) => {
}
}

/**
* @template {keyof import('@rm/types').AllFilters} T
* @param {import('@rm/types').AllFilters[T]} requestedFilters
* @param {Record<string, any>} userSettings
* @param {T} category
* @param {string[]} [onlyAreas]
* @returns
*/
const trimFilters = (requestedFilters, userSettings, category, onlyAreas) => {
const { filters: staticFilters } = useStatic.getState()
const easyMode = !!requestedFilters?.easyMode
Expand All @@ -53,11 +61,14 @@ const trimFilters = (requestedFilters, userSettings, category, onlyAreas) => {
entryV
}
})
Object.entries(requestedFilters.filter).forEach((filter) => {
const [id, specifics] = filter
Object.entries(requestedFilters.filter).forEach(([id, specifics]) => {
// eslint-disable-next-line no-unused-vars
const { enabled, size, ...rest } = (easyMode
? requestedFilters.ivOr
: specifics) || { all: false, adv: '' }

if (specifics && specifics.enabled && staticFilters[category]?.filter[id]) {
trimmed[id] = easyMode ? requestedFilters.ivOr : specifics
trimmed[id] = rest
}
})
return trimmed
Expand Down

0 comments on commit 706581b

Please sign in to comment.