1
0
mirror of https://github.com/pi-hole/pi-hole synced 2025-01-20 13:01:08 +00:00

optimise gravity list inserts

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
Adam Warner 2019-12-09 22:30:41 +00:00
parent 1f03faddef
commit d29947ba32
No known key found for this signature in database
GPG Key ID: 872950F3ECF2B173

View File

@ -139,6 +139,12 @@ database_table_from_file() {
local rowid local rowid
declare -i rowid declare -i rowid
rowid=1 rowid=1
if [[ "${table}" == "gravity" ]]; then
#Append ,${arg} to every line and then remove blank lines before import
sed -e "s/$/,${arg}/" "${source}" > "${tmpFile}"
sed -i '/^$/d' "${tmpFile}"
else
grep -v '^ *#' < "${source}" | while IFS= read -r domain grep -v '^ *#' < "${source}" | while IFS= read -r domain
do do
# Only add non-empty lines # Only add non-empty lines
@ -146,9 +152,6 @@ database_table_from_file() {
if [[ "${table}" == "domain_audit" ]]; then if [[ "${table}" == "domain_audit" ]]; then
# domain_audit table format (no enable or modified fields) # domain_audit table format (no enable or modified fields)
echo "${rowid},\"${domain}\",${timestamp}" >> "${tmpFile}" echo "${rowid},\"${domain}\",${timestamp}" >> "${tmpFile}"
elif [[ "${table}" == "gravity" ]]; then
# gravity table format
echo "\"${domain}\",${arg}" >> "${tmpFile}"
else else
# White-, black-, and regexlist format # White-, black-, and regexlist format
echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${source}\"" >> "${tmpFile}" echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${source}\"" >> "${tmpFile}"
@ -156,6 +159,9 @@ database_table_from_file() {
rowid+=1 rowid+=1
fi fi
done done
fi
inputfile="${tmpFile}" inputfile="${tmpFile}"
# Store domains in database table specified by ${table} # Store domains in database table specified by ${table}