The two outputs you provided show that the dig through Pi-hole is going to the encrypted upstream DNS? Or to 8.8.8.8? I assume Cloudflare since this is what is configured in the debug log you provided.
We can take the Pi-hole out of the process with this command and see if the delay is in the encrypted DNS service.
That's what I thought when I set it up! That the pi-hole would always reach out to cloudflare no matter what.
Unfortunately in my attempts to resolve this issue I may have changed other settings and with the delay in settings propagating I may be falsely attributing resolving this to the wrong change.
I'll be sure to keep an eye out and continuously monitor DNS query times for this problem to show its ugly head again.
I don't know if I am late here, but I am using my UniFi Dream Machine Pro with a Pi-hole installation.
I set the IP for my Raspberry Pi on both the LAN and WAN settings, as the only DNS server, as I found that if I only defined it in the LAN section, clients would still use the WAN automatic DNS server.
I am getting regular lookup times, see below for reddit.
; <<>> DiG 9.10.6 <<>> reddit.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28864
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;reddit.com. IN A
;; ANSWER SECTION:
reddit.com. 16 IN A 151.101.129.140
reddit.com. 16 IN A 151.101.1.140
reddit.com. 16 IN A 151.101.65.140
reddit.com. 16 IN A 151.101.193.140
;; Query time: 2 msec
;; SERVER: 192.168.1.45#53(192.168.1.45)
;; WHEN: Wed Jul 22 18:41:53 WEST 2020
;; MSG SIZE rcvd: 103