mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +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:
parent
fb72ac9904
commit
294df8690c
1 changed files with 8 additions and 2 deletions
10
pihole
10
pihole
|
@ -67,14 +67,20 @@ setupLCDFunction() {
|
|||
exit 0
|
||||
}
|
||||
|
||||
scanList(){
|
||||
grep -E "(^|\s)${domain}($|\s)" "$1"
|
||||
}
|
||||
|
||||
queryFunc() {
|
||||
domain="${2}"
|
||||
lists=( /etc/pihole/list.* /etc/pihole/blacklist.txt)
|
||||
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)"
|
||||
if [[ ${count} > 0 ]]; then
|
||||
grep -E "(^|\s)${domain}($|\s)" ${list}
|
||||
echo $result
|
||||
fi
|
||||
echo ""
|
||||
done
|
||||
|
|
Loading…
Reference in a new issue