Prevent extra fetches when not required
This commit is contained in:
parent
1191e71a15
commit
2ef014b070
|
@ -45,14 +45,25 @@
|
||||||
$: expandedDefaultValue = expand(defaultValue)
|
$: expandedDefaultValue = expand(defaultValue)
|
||||||
$: primaryDisplay = tableDefinition?.primaryDisplay || "_id"
|
$: primaryDisplay = tableDefinition?.primaryDisplay || "_id"
|
||||||
|
|
||||||
let prevTerm
|
let lastFetchedTerm
|
||||||
$: {
|
$: {
|
||||||
// Check if the fetch changed, ignoring differences between empty/null/undefined
|
const termChangedSinceFetch = (lastFetchedTerm || "") !== (fetchTerm || "")
|
||||||
if (primaryDisplay && prevTerm != fetchTerm) {
|
|
||||||
prevTerm = fetchTerm
|
const allRowsFetched =
|
||||||
fetch.update({
|
!lastFetchedTerm && $fetch.rows.length === $fetch.totalRows
|
||||||
query: { string: { [primaryDisplay]: fetchTerm } },
|
if (!allRowsFetched && termChangedSinceFetch) {
|
||||||
})
|
debugger
|
||||||
|
// Don't request until we have the primary display
|
||||||
|
if (primaryDisplay) {
|
||||||
|
lastFetchedTerm = fetchTerm
|
||||||
|
fetch.update({
|
||||||
|
query: { string: { [primaryDisplay]: fetchTerm } },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
options = fetchTerm
|
||||||
|
? $fetch.rows.filter(row => row[primaryDisplay].includes(fetchTerm))
|
||||||
|
: $fetch.rows
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue