# HG changeset patch # User Pascal Bellard # Date 1343329927 -7200 # Node ID 87afe4f1486df3fc6fd046d2fc32c1c2f303c201 # Parent d35926c24766226c5a7fc0af633478df5c17770a mirror-search.sh: be less cpu hungry... diff -r d35926c24766 -r 87afe4f1486d pkgs/mirror-search.sh --- a/pkgs/mirror-search.sh Mon Jul 16 18:48:52 2012 +0000 +++ b/pkgs/mirror-search.sh Thu Jul 26 21:12:07 2012 +0200 @@ -1,9 +1,13 @@ #!/bin/sh + # Tiny CGI search engine for SliTaz packages on http://pkgs.slitaz.org/ # Christophe Lincoln +# Pascal Bellard # Aleksej Bobylev # +renice -n 19 $$ + # Parse query string . /usr/lib/slitaz/httphelper.sh @@ -216,11 +220,27 @@ . lib/header.sh } +cat_files_list() +{ + local tmp=/tmp/files.list.$(basename ${1%/packages}) + if [ ! -s $tmp -o $1/files.list.lzma -nt $tmp ]; then + unlzma -c $1/files.list.lzma > $tmp.$$ && mv $tmp.$$ $tmp + fi + case "$2" in + lines) if [ ! -s $tmp.lines -o $tmp -nt $tmp.lines ]; then + cat $tmp | wc -l > $tmp.lines.$$ && + mv $tmp.lines.$$ $tmp.lines + fi + cat $tmp.lines ;; + *) cat $tmp ;; + esac +} + # xHTML Footer. # TODO: caching the summary for 5 minutes xhtml_footer() { PKGS=$(ls $WOK/ | wc -l) - FILES=$(unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | wc -l) + FILES=$(cat_files_list $PACKAGES_REPOSITORY lines) . lib/footer.sh } @@ -584,8 +604,8 @@

$(eval_gettext "These packages may overload files of \$SEARCH")

 _EOT_
-		( unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | grep ^$SEARCH: ;
-		  unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | grep -v ^$SEARCH: ) | awk '
+		( cat_files_list $PACKAGES_REPOSITORY | grep ^$SEARCH: ;
+		  cat_files_list $PACKAGES_REPOSITORY | grep -v ^$SEARCH: ) | awk '
 BEGIN { pkg=""; last="x" }
 {
 	if ($2 == "") next
@@ -613,7 +633,7 @@
 
 _EOT_
 		last=""
-		unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
+		cat_files_list $PACKAGES_REPOSITORY \
 		| grep "$SEARCH" | while read pkg file; do
 			echo "$file" | grep -q "$SEARCH" || continue
 			if [ "$last" != "${pkg%:}" ]; then
@@ -644,13 +664,13 @@
 
 _EOT_
 		last=""
-		unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
+		cat_files_list $PACKAGES_REPOSITORY \
 		| grep ^$SEARCH: |  sed 's/.*: /    /' | sort
 		cat << _EOT_
 
 _EOT_
-		filenb=$(unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | grep ^$SEARCH: | wc -l)
+		filenb=$(cat_files_list $PACKAGES_REPOSITORY | grep ^$SEARCH: | wc -l)
 		eval_ngettext "\$filenb file" "\$filenb files" $filenb
 		cat << _EOT_
   \