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