mirror of
https://github.com/pi-hole/pi-hole
synced 2025-01-05 05:30:55 +00:00
Speedup api response handling (#5833)
This commit is contained in:
commit
b964657b62
@ -165,15 +165,17 @@ GetFTLData() {
|
|||||||
# get the data from querying the API as well as the http status code
|
# get the data from querying the API as well as the http status code
|
||||||
response=$(curl -skS -w "%{http_code}" -X GET "${API_URL}$1" -H "Accept: application/json" -H "sid: ${SID}" )
|
response=$(curl -skS -w "%{http_code}" -X GET "${API_URL}$1" -H "Accept: application/json" -H "sid: ${SID}" )
|
||||||
|
|
||||||
# status are the last 3 characters
|
|
||||||
status="${response#"${response%???}"}"
|
|
||||||
# data is everything from response without the last 3 characters
|
|
||||||
data="${response%???}"
|
|
||||||
|
|
||||||
if [ "${2}" = "raw" ]; then
|
if [ "${2}" = "raw" ]; then
|
||||||
# return the raw response
|
# return the raw response
|
||||||
echo "${response}"
|
echo "${response}"
|
||||||
else
|
else
|
||||||
|
|
||||||
|
# status are the last 3 characters
|
||||||
|
# not using ${response#"${response%???}"}" here because it's extremely slow on big responses
|
||||||
|
status=$(printf "%s" "${response}" | tail -c 3)
|
||||||
|
# data is everything from response without the last 3 characters
|
||||||
|
data="${response%???}"
|
||||||
|
|
||||||
# return only the data
|
# return only the data
|
||||||
if [ "${status}" = 200 ]; then
|
if [ "${status}" = 200 ]; then
|
||||||
# response OK
|
# response OK
|
||||||
@ -264,7 +266,8 @@ apiFunc() {
|
|||||||
response=$(GetFTLData "$1" raw)
|
response=$(GetFTLData "$1" raw)
|
||||||
|
|
||||||
# status are the last 3 characters
|
# status are the last 3 characters
|
||||||
status="${response#"${response%???}"}"
|
# not using ${response#"${response%???}"}" here because it's extremely slow on big responses
|
||||||
|
status=$(printf "%s" "${response}" | tail -c 3)
|
||||||
# data is everything from response without the last 3 characters
|
# data is everything from response without the last 3 characters
|
||||||
data="${response%???}"
|
data="${response%???}"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user