1
0
mirror of https://github.com/pi-hole/pi-hole synced 2025-01-03 12:40:56 +00:00

Do only one grep on each of the lists and count the number of non-empty lines in the result. Improves speed by factor of 2x

This commit is contained in:
DL6ER 2016-12-06 09:55:17 +01:00
parent fb72ac9904
commit 294df8690c

10
pihole
View File

@ -67,14 +67,20 @@ setupLCDFunction() {
exit 0 exit 0
} }
scanList(){
grep -E "(^|\s)${domain}($|\s)" "$1"
}
queryFunc() { queryFunc() {
domain="${2}" domain="${2}"
lists=( /etc/pihole/list.* /etc/pihole/blacklist.txt) lists=( /etc/pihole/list.* /etc/pihole/blacklist.txt)
for list in ${lists[@]}; do for list in ${lists[@]}; do
count=$(grep -c -E "(^|\s)${domain}($|\s)" $list) result=$(scanList $list)
# Remove empty lines before couting number of results
count=$(sed '/^\s*$/d' <<< "$result" | wc -l)
echo "::: ${list} (${count} results)" echo "::: ${list} (${count} results)"
if [[ ${count} > 0 ]]; then if [[ ${count} > 0 ]]; then
grep -E "(^|\s)${domain}($|\s)" ${list} echo $result
fi fi
echo "" echo ""
done done