slitaz-forge rev 321

mirror-search.sh: be less cpu hungry...
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Jul 26 21:12:07 2012 +0200 (2012-07-26)
parents d35926c24766
children 11b633eddc25
files pkgs/mirror-search.sh
line diff
     1.1 --- a/pkgs/mirror-search.sh	Mon Jul 16 18:48:52 2012 +0000
     1.2 +++ b/pkgs/mirror-search.sh	Thu Jul 26 21:12:07 2012 +0200
     1.3 @@ -1,9 +1,13 @@
     1.4  #!/bin/sh
     1.5 +
     1.6  # Tiny CGI search engine for SliTaz packages on http://pkgs.slitaz.org/
     1.7  # Christophe Lincoln <pankso@slitaz.org>
     1.8 +# Pascal Bellard <pascal.bellard@slitaz.org>
     1.9  # Aleksej Bobylev <al.bobylev@gmail.com>
    1.10  #
    1.11  
    1.12 +renice -n 19 $$
    1.13 +
    1.14  # Parse query string
    1.15  . /usr/lib/slitaz/httphelper.sh
    1.16  
    1.17 @@ -216,11 +220,27 @@
    1.18  	. lib/header.sh
    1.19  }
    1.20  
    1.21 +cat_files_list()
    1.22 +{
    1.23 +	local tmp=/tmp/files.list.$(basename ${1%/packages})
    1.24 +	if [ ! -s $tmp -o $1/files.list.lzma -nt $tmp ]; then
    1.25 +		unlzma -c $1/files.list.lzma > $tmp.$$ && mv $tmp.$$ $tmp
    1.26 +	fi
    1.27 +	case "$2" in
    1.28 +	lines)	if [ ! -s $tmp.lines -o $tmp -nt $tmp.lines ]; then
    1.29 +			cat $tmp | wc -l > $tmp.lines.$$ &&
    1.30 +			mv $tmp.lines.$$ $tmp.lines
    1.31 +		fi
    1.32 +		cat $tmp.lines ;;	
    1.33 +	*)	cat $tmp ;;
    1.34 +	esac
    1.35 +}
    1.36 +
    1.37  # xHTML Footer.
    1.38  # TODO: caching the summary for 5 minutes
    1.39  xhtml_footer() {
    1.40  	PKGS=$(ls $WOK/ | wc -l)
    1.41 -	FILES=$(unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | wc -l)
    1.42 +	FILES=$(cat_files_list $PACKAGES_REPOSITORY lines)
    1.43  	. lib/footer.sh
    1.44  }
    1.45  
    1.46 @@ -584,8 +604,8 @@
    1.47  <h3>$(eval_gettext "These packages may overload files of \$SEARCH")</h3>
    1.48  <pre>
    1.49  _EOT_
    1.50 -		( unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | grep ^$SEARCH: ;
    1.51 -		  unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | grep -v ^$SEARCH: ) | awk '
    1.52 +		( cat_files_list $PACKAGES_REPOSITORY | grep ^$SEARCH: ;
    1.53 +		  cat_files_list $PACKAGES_REPOSITORY | grep -v ^$SEARCH: ) | awk '
    1.54  BEGIN { pkg=""; last="x" }
    1.55  {
    1.56  	if ($2 == "") next
    1.57 @@ -613,7 +633,7 @@
    1.58  <pre>
    1.59  _EOT_
    1.60  		last=""
    1.61 -		unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
    1.62 +		cat_files_list $PACKAGES_REPOSITORY \
    1.63  		| grep "$SEARCH" | while read pkg file; do
    1.64  			echo "$file" | grep -q "$SEARCH" || continue
    1.65  			if [ "$last" != "${pkg%:}" ]; then
    1.66 @@ -644,13 +664,13 @@
    1.67  <pre>
    1.68  _EOT_
    1.69  		last=""
    1.70 -		unlzma -c $PACKAGES_REPOSITORY/files.list.lzma \
    1.71 +		cat_files_list $PACKAGES_REPOSITORY \
    1.72  		| grep ^$SEARCH: |  sed 's/.*: /    /' | sort
    1.73  		cat << _EOT_
    1.74  </pre>
    1.75  <pre>
    1.76  _EOT_
    1.77 -		filenb=$(unlzma -c $PACKAGES_REPOSITORY/files.list.lzma | grep ^$SEARCH: | wc -l)
    1.78 +		filenb=$(cat_files_list $PACKAGES_REPOSITORY | grep ^$SEARCH: | wc -l)
    1.79  		eval_ngettext "\$filenb file" "\$filenb files" $filenb
    1.80  		cat << _EOT_
    1.81    \