optimize autocomplete

pull/220/head^2
Pete Matsyburka 2 years ago
parent 801abd197b
commit 6ca44a5cc3

@ -24,9 +24,9 @@ module Api
if SELECT_COLUMNS.include?(params[:field])
column = Submitter.arel_table[params[:field].to_sym]
term = "%#{params[:q].downcase}%"
term = "#{params[:q].downcase}%"
submitters.where(column.lower.matches(term))
submitters.where(column.matches(term, false, true))
else
Submitters.search(submitters, params[:q])
end

@ -37,7 +37,9 @@ export default class extends HTMLElement {
if (q) {
const queryParams = new URLSearchParams({ q, field: this.dataset.field })
fetch('/api/submitters_autocomplete?' + queryParams).then(async (resp) => {
this.currentFetch ||= fetch('/api/submitters_autocomplete?' + queryParams)
this.currentFetch.then(async (resp) => {
const items = await resp.json()
if (q.length < 3) {
@ -47,6 +49,8 @@ export default class extends HTMLElement {
}
}).catch(() => {
resolve([])
}).finally(() => {
this.currentFetch = null
})
} else {
resolve([])

Loading…
Cancel
Save