InfluxDb Query in Grafana is taking time to get result using filter

Backend is Influxdb and when querying the filtering takes too much time .
How to make this query fast so that grafana can load it faster.

or any other way to filter records

Query

from(bucket: “general”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “mem”)
|> filter(fn: (r) => r[“_field”] == “device_temperature”)
|> group(columns: [“host”])

|> filter(fn: (r) => r[“host”] =~ /^(BC572903FCE6|BC572903FCB2|BC572903FCDD|BC572903FCD6|BC572903FC92|BC572903FC8D|BC572903FC7F|BC572903FC89|BC572903FCBE|BC572903FC89|BC572903FCF2|BC572903FCF9|BC572903FC8A|BC572903FC93|BC572903FCC3|BC572903FC6F|BC572903FC73BC572903FCE6|BC572903FCB2|BC572903FCDD|BC572903FCD6|BC572903FC92|BC572903FC8D|BC572903FC7F|BC572903FC89|BC572903FCBE|BC572903FC89|BC572903FCF2|BC572903FCF9|BC572903FC8A|BC572903FC93|BC572903FCC3|BC572903FC6F|BC572903FC73)$/) |> map(fn: (r) => ({r with host:
if r.host == “” then “”
else if r.host == “BC572903FCE6” then “3R801-FCE6”
else if r.host == “BC572903FCB2” then “3R802-FCB2”
else if r.host == “BC572903FCDD” then “3R803-FCDD”
else if r.host == “BC572903FCD6” then “3R804-FCD6”
else if r.host == “BC572903FC92” then “3R805-FC92”
else if r.host == “BC572903FC8D” then “3R806-FC8D”
else if r.host == “BC572903FC7F” then “3R807-FC7F”
else if r.host == “BC572903FC89” then “3R808-FC89”
else if r.host == “BC572903FCBE” then “3R808-FCBE”
else if r.host == “BC572903FC89” then “3R808-FC89”
else if r.host == “BC572903FCF2” then “3R809-FCF2”
else if r.host == “BC572903FCF9” then “3R810-FCF9”
else if r.host == “BC572903FC8A” then “3R811-FC8A”
else if r.host == “BC572903FC93” then “3R812-FC93”
else if r.host == “BC572903FCC3” then “3R813-FCC3”
else if r.host == “BC572903FC6F” then “3R814-FC6F”
else if r.host == “BC572903FC73” then “3R815-FC73”
else “”}))
|> drop(columns: [“_field”, “device_temperature”])
|> drop(columns: [“_field”, “clockin”])
|> drop(columns: [“_field”, “gateway_insert”])
|> drop(columns: [“_field”, “location”])
|> drop(columns: [“_field”, “history”])
|> aggregateWindow(every: 5m, fn: mean, createEmpty: false)
|> yield(name: “mean”)