Browse Source

Merge 873df1f36d into 4af4c948e9

pull/3104/merge
Samuel Young 3 days ago committed by GitHub
parent
commit
f7f8fca03d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 18
      app/frontend/controllers/address_search_controller.js
  2. 2
      app/services/address_client.rb
  3. 2
      app/services/uprn_client.rb

18
app/frontend/controllers/address_search_controller.js

@ -4,10 +4,28 @@ import 'accessible-autocomplete/dist/accessible-autocomplete.min.css'
const options = []
let latestQueryId = 0
const sleep = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms))
}
const fetchOptions = async (query, searchUrl) => {
if (query.length < 2) {
throw new Error('Query must be at least 2 characters long.')
}
// implement a debounce
// this is because this API has periods of high latency if OS Places has an outage
// making too many requests can overwhelm the number of threads available on the server
// which can in turn cause a site wide outage
latestQueryId++
const myQueryId = latestQueryId
await sleep(500)
if (myQueryId !== latestQueryId) {
throw new Error('Outdated query, ignoring result.')
}
try {
const response = await fetch(`${searchUrl}?query=${encodeURIComponent(query.trim())}`)
return await response.json()

2
app/services/address_client.rb

@ -35,7 +35,7 @@ private
client.use_ssl = true
client.verify_mode = OpenSSL::SSL::VERIFY_PEER
client.max_retries = 3
client.read_timeout = 30 # seconds
client.read_timeout = 15 # seconds
client
end

2
app/services/uprn_client.rb

@ -39,7 +39,7 @@ private
client.use_ssl = true
client.verify_mode = OpenSSL::SSL::VERIFY_PEER
client.max_retries = 3
client.read_timeout = 30 # seconds
client.read_timeout = 20 # seconds
client
end

Loading…
Cancel
Save