summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2019-05-10 21:29:07 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2019-05-10 21:29:07 +0200
commitacc93c12198350212241dd88be572da042834792 (patch)
tree940e16c19fc656161d4c1477d63fe8a542714c3e
parent51c35cf03bc6b30b3a8fec6091e5d9eba422f62e (diff)
sfeed_opml_export: optimize
Tested using 1000 feeds, took about 20s, now 0.02s. The overhead of sed and printf was too high. Now pipe an intermediate TAB format to awk and print it in one stage.
-rwxr-xr-xsfeed_opml_export29
1 files changed, 14 insertions, 15 deletions
diff --git a/sfeed_opml_export b/sfeed_opml_export
index 5d88165..82704a6 100755
--- a/sfeed_opml_export
+++ b/sfeed_opml_export
@@ -22,21 +22,11 @@ loadconfig() {
fi
}
-# escape(s)
-escape() {
- printf '%s' "$1" | sed -e 's@&@\&amp;@g' -e 's@"@\&quot;@g'\
- -e "s@'@\&#39;@g" -e 's@<@\&lt;@g' -e 's@>@\&gt;@g'
-}
-
# override feeds function to ouput opml XML.
# feed(name, feedurl, [basesiteurl], [encoding])
feed() {
- name=$(escape "$1")
- xmlurl=$(escape "$2")
- htmlurl=$(escape "$3")
-
- printf '\t<outline title="%s" text="%s" xmlUrl="%s" htmlUrl="%s"/>\n' \
- "${name}" "${name}" "${xmlurl}" "${htmlurl}"
+ # NOTE: TABs in field values are unsupported, be sane.
+ echo "$1 $2 $3"
}
# load config file.
@@ -51,9 +41,18 @@ cat <<!
<body>
!
-feeds
-# wait till all items are processed (concurrently).
-wait
+feeds | LC_ALL=C awk 'BEGIN {
+ FS = OFS = "\t";
+}
+{
+ gsub("&", "\\&amp;");
+ gsub("\"", "\\&quot;");
+ gsub("'"'"'", "\\&#39;");
+ gsub("<", "\\&lt;");
+ gsub(">", "\\&gt;");
+
+ print "\t<outline title=\"" $1 "\" text=\""$1"\" xmlUrl=\""$2"\" htmlUrl=\""$3"\"/>";
+}'
cat <<!
</body>