From 12c83ad8f3ac1a3178ced9dbd82c3b6e078a06b9 Mon Sep 17 00:00:00 2001 From: paul Date: Wed, 20 Apr 2016 13:24:48 +0000 Subject: [PATCH] maintain different top lists for tag selection and setting svn path=/trunk/; revision=120 --- actions/meta.sh | 2 +- actions/multitag.sh | 2 +- pages/common.sh | 95 +++++++++++++++++++++++++-------------- pages/list.sh | 2 +- pages/quicklinks.sh | 2 +- templates/playctl.html.sh | 2 +- templates/tagger.html.sh | 2 +- templates/view.html.sh | 2 +- 8 files changed, 68 insertions(+), 41 deletions(-) diff --git a/actions/meta.sh b/actions/meta.sh index f2e2431..127e03e 100755 --- a/actions/meta.sh +++ b/actions/meta.sh @@ -52,7 +52,7 @@ ${description} EOF rm "${_DATA}/cache/$info.cache" 2>/dev/null rm ${_DATA}/cache/\?* 2>/dev/null - rm ${_DATA}/cache/taglist 2>/dev/null + rm ${_DATA}/cache/taglist_set ${_DATA}/cache/taglist_filter 2>/dev/null fi redirect "?i=&pn=${page}&s=${search}&f=${filter}&o=${order}#${info}" diff --git a/actions/multitag.sh b/actions/multitag.sh index c5a8df1..767f289 100755 --- a/actions/multitag.sh +++ b/actions/multitag.sh @@ -62,6 +62,6 @@ while [ -n "${_POST[tagsel$n]}" ]; do done rm "${_DATA}"/cache/\?* 2>/dev/null -[ -n "${_POST[tags]}" ] && rm "${_DATA}"/cache/taglist 2>/dev/null +[ -n "${_POST[tags]}" ] && rm "${_DATA}"/cache/taglist_set "${_DATA}"/cache/taglist_filter 2>/dev/null redirect "?o=$order&s=$search&f=$filter&pn=$page" diff --git a/pages/common.sh b/pages/common.sh index 0d33ee4..ba4cf27 100755 --- a/pages/common.sh +++ b/pages/common.sh @@ -33,44 +33,71 @@ page_link='' page_next="${page_link}pn=$(($page + $pagesize))" page_this="${page_link}pn=$page" -taglist=$( -if [ -r ${_DATA}/cache/taglist ]; then - cat ${_DATA}/cache/taglist -else - truncate -s0 ${_DATA}/cache/taglist - truncate -s0 ${_DATA}/cache/tagnorm - (for each in ${_DATA}/meta/*.meta; do - sed -n '2s:|:\n:gp' "$each" - done \ - | sort - printf \\n - ) | (while read tag; do - if [ "$tag" = "$lasttag" ]; then - tagcount=$(( ${tagcount:-0} + 1 )) - else - [ -n "$lasttag" ] && printf %s\\t%s\\n "$tagcount" "$lasttag" - tagcount=1 - fi - lasttag="$tag" - done \ - | sort -rn - printf \\n - ) | while read x tag; do - topcnt=$(grep "${tag%%:*}" ${_DATA}/cache/taglist |wc -l) - [ $topcnt -lt 10 ] \ - && printf %s\\n "$tag" >>${_DATA}/cache/taglist \ - || printf %s\\n "$tag" >>${_DATA}/cache/tagnorm - done - cat ${_DATA}/cache/taglist - sort ${_DATA}/cache/tagnorm \ - | tee -a ${_DATA}/cache/taglist - rm ${_DATA}/cache/tagnorm -fi +taglist_set=$( + if [ -r ${_DATA}/cache/taglist_set ]; then + cat ${_DATA}/cache/taglist_set + else + truncate -s0 ${_DATA}/cache/taglist_set + truncate -s0 ${_DATA}/cache/tagnorm + + ( sed -sn '2s;|;\n;gp' "${_DATA}/meta/"*.meta \ + | sort + printf \\n + ) | while read tag; do + if [ "$tag" = "$lasttag" ]; then + tagcount=$(( ${tagcount:-0} + 1 )) + else + [ -n "$lasttag" ] && printf '%s\t%s\n' "$tagcount" "$lasttag" + tagcount=1 + fi + lasttag="$tag" + done \ + | sort -rn \ + | while read x tag; do + topcnt=$(grep -c "${tag%%:*}" ${_DATA}/cache/taglist_set) + [ $topcnt -lt 10 ] \ + && printf %s\\n "$tag" >>${_DATA}/cache/taglist_set \ + || printf %s\\n "$tag" >>${_DATA}/cache/tagnorm + done + + cat ${_DATA}/cache/taglist_set + sort ${_DATA}/cache/tagnorm \ + | tee -a ${_DATA}/cache/taglist_set + rm ${_DATA}/cache/tagnorm + fi +) + +taglist_filter=$( + if [ -r ${_DATA}/cache/taglist_filter ]; then + cat ${_DATA}/cache/taglist_filter + else + truncate -s0 ${_DATA}/cache/taglist_filter + truncate -s0 ${_DATA}/cache/tagnorm + + sed -sn '2s;|;\n;gp' "${_DATA}/meta/"*.meta \ + | sort -u \ + | while read tag; do + cnt="$(grep -cF "$tag" ${_DATA}/meta/recent)" + printf '%s\t%s\n' "$cnt" "$tag" + done \ + | sort -rn \ + | while read x tag; do + topcnt=$(grep -c "${tag%%:*}" ${_DATA}/cache/taglist_filter) + [ $topcnt -lt 10 ] \ + && printf %s\\n "$tag" >>${_DATA}/cache/taglist_filter \ + || printf %s\\n "$tag" >>${_DATA}/cache/tagnorm + done + + cat ${_DATA}/cache/taglist_filter + sort ${_DATA}/cache/tagnorm \ + | tee -a ${_DATA}/cache/taglist_filter + rm ${_DATA}/cache/tagnorm + fi ) list_categories(){ printf none\\n - printf %s "$taglist" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u + printf %s "$taglist_filter" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u } genthumb(){ diff --git a/pages/list.sh b/pages/list.sh index 2c4b1f1..4d25103 100755 --- a/pages/list.sh +++ b/pages/list.sh @@ -44,7 +44,7 @@ category_selected(){ filter="$2" [ "$cat" = "none:" ] && cat='' - printf %s "$taglist" \ + printf %s "$taglist_filter" \ | sed -r 's;^('"$filter"')$;1 &;;t;s;^;0 ;' \ | sed -rn 's;^(0|1) '"$cat"'([^:]+)$;\1 \2;p' \ | sed 's;^0 ;;' diff --git a/pages/quicklinks.sh b/pages/quicklinks.sh index e46d930..f22a412 100755 --- a/pages/quicklinks.sh +++ b/pages/quicklinks.sh @@ -52,7 +52,7 @@ category_selected(){ filter="$2" [ "$cat" = "none:" ] && cat='' - printf %s "$taglist" \ + printf %s "$taglist_filter" \ | sed -r 's;^('"$filter"')$;1 &;;t;s;^;0 ;' \ | sed -rn 's;^(0|1) '"$cat"'([^:]+)$;\1 \2;p' \ | sed 's;^0 ;;' diff --git a/templates/playctl.html.sh b/templates/playctl.html.sh index f073800..7ef0700 100755 --- a/templates/playctl.html.sh +++ b/templates/playctl.html.sh @@ -78,7 +78,7 @@ cat <%s' \ "$(egrep -q "(^|.*\|)$line(\|.*|$)" "$meta" && printf selected)" \ "$line" "${line#*:}" diff --git a/templates/tagger.html.sh b/templates/tagger.html.sh index 10ed787..f92bf0c 100755 --- a/templates/tagger.html.sh +++ b/templates/tagger.html.sh @@ -19,7 +19,7 @@ category_options(){ cat="${1}:" [ "$cat" = "none:" ] && cat='' - printf %s "$taglist" \ + printf %s "$taglist_set" \ | sed -rn 's;^('"$cat"')([^:]+)$;;p' } diff --git a/templates/view.html.sh b/templates/view.html.sh index 46a1d41..8df1b56 100755 --- a/templates/view.html.sh +++ b/templates/view.html.sh @@ -64,7 +64,7 @@ cat <%s' \ "$(egrep -q "(^|.*\|)$line(\|.*|$)" "$meta" && printf selected)" \ "$line" "${line#*:}" -- 2.39.2