From 4fa45dcb5617057ce673d3db42b941aae9f66271 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Tue, 24 Jul 2018 00:18:42 +0200 Subject: [PATCH] page caching --- list.sh | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/list.sh b/list.sh index 25822e4..1a5a6cf 100644 --- a/list.sh +++ b/list.sh @@ -10,7 +10,7 @@ list_item() { if [ "$type" = dir ]; then name="${meta%% *}"; display="$(HTML "$name")"; link="$(URL "$ITEM/$name")" - printf '[a .list .dir href="%s" %s]' "${link}?${w_reflink#*?}" "$name" + printf '[a .list .dir href="%s" %s]' "${link}?${w_refuri#*\?}" "$name" return 0 fi @@ -104,24 +104,34 @@ list_order(){ } list_filemeta(){ - local meta base cbase fm + local meta base cbase fm cachename base="$1" meta="$_DATA/$ITEM/$base/.index/meta" - cbase="$(STRING "$base")" meta_dir "$_DATA/$ITEM/$base" - grep -axE '[0-9]+ [0-9]+ [0-9]+ tags=[^ ]* comment=[^ ]* .+' "$meta" \ - | while read -r fm; do - printf '%s %s/%s\n' "${fm% *}" "$cbase" "${fm##* }" - done + cachename="$(printf '%s\n' "$mode" "$FILTER" "$SEARCH" "$ORDER" |sha1sum)" + cachename="$_DATA/$ITEM/.index/${cachename% -}.cache" + + if [ "$cachename" -nt "$meta" ] 2>&-; then + cat "$cachename" + else + cbase="$(STRING "$base")" + grep -axE '[0-9]+ [0-9]+ [0-9]+ tags=[^ ]* comment=[^ ]* .+' "$meta" \ + | while read -r fm; do + printf '%s %s/%s\n' "${fm% *}" "$cbase" "${fm##* }" + done \ + | list_filter \ + | list_order \ + | { [ -d "${meta%meta}" ] && tee "$cachename" || cat; } + fi } list_items() { local mode meta mode="$(COOKIE mode |grep -m1 -axE 'index|browse' || printf browse )" - + if [ "$mode" = browse ]; then - [ "$ITEM" ] && printf '..\n' + [ "$ITEM" ] && printf 'dir\t..\n' (cd "$_DATA/$ITEM"; find ./ -type d \! -name .index -mindepth 1 -maxdepth 1 \ ) | cut -d/ -f2- | sort |sed 's;^;dir\t;;' @@ -136,9 +146,10 @@ list_items() { } list_paginate() { - local page i c n end + local page i c n end qry page="$(GET p |grep -axE '[0-9]+' || printf 1)"; c=1 end=$((page + LISTSIZE)) + qry="${w_refuri#*\?}"; qry="${qry#p=*&}" printf '[div .itemlist ' while read -r i; do @@ -150,7 +161,7 @@ list_paginate() { printf '[div .pagination' for n in $( seq 1 $((c / LISTSIZE + 1)) ); do printf '[a .page href="%s" %s]' \ - "?p=$(( (n - 1) * LISTSIZE + 1))&$qry" "$n" + "?p=$(( (n - 1) * LISTSIZE + 1))&${qry}" "$n" done printf ']' } @@ -176,8 +187,6 @@ printf 'Content-Type: text/html;charset=utf-8\r\n\r\n' printf ' [form method=POST action="?a=multitag"' list_items \ - | list_filter \ - | list_order \ | list_paginate printf ' [div #editing -- 2.39.2