From: Paul Hänsch Date: Sun, 21 May 2023 09:56:56 +0000 (+0200) Subject: speed improvement: save fork when checking mdfile existence X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=ac6c98bd35d32425608eaafe1cbf2efcd38a478a;p=shellwiki speed improvement: save fork when checking mdfile existence --- diff --git a/handlers/20_page.sh b/handlers/20_page.sh index 87af685..eb894c2 100755 --- a/handlers/20_page.sh +++ b/handlers/20_page.sh @@ -56,7 +56,7 @@ case "${PATH_INFO}" in return 1 ;; */) - if [ ! "$(mdfile "$PATH_INFO")" ]; then + if ! mdfile "$PATH_INFO" >&-; then theme_error 404 elif ! acl_read "$PATH_INFO"; then theme_error 403 diff --git a/handlers/90_brackets.sh b/handlers/90_brackets.sh index 1f11cf4..ce49b0e 100755 --- a/handlers/90_brackets.sh +++ b/handlers/90_brackets.sh @@ -11,7 +11,7 @@ case "${PATH_INFO}" in REDIRECT "${_BASE}${PATH_INFO%\[view\]}" ;; */) - if [ ! "$(mdfile "${PATH_INFO}")" ]; then + if ! mdfile "${PATH_INFO}" >&-; then theme_error 404 elif ! acl_read "${PATH_INFO}"; then theme_error 403 diff --git a/themes/default.sh b/themes/default.sh index 7c31003..3812f06 100755 --- a/themes/default.sh +++ b/themes/default.sh @@ -171,7 +171,7 @@ theme_error(){ 500) printf "%s\r\n" "Status: 500 Internal Server Error";; esac - if [ "$(mdfile "/[wiki]/$errno/")" ]; then + if mdfile "/[wiki]/$errno/" >&-; then theme_page "/[wiki]/$errno/" else printf "Content-Length: 0\r\n\r\n" diff --git a/tools.sh b/tools.sh index c5545fb..de055fe 100755 --- a/tools.sh +++ b/tools.sh @@ -12,15 +12,21 @@ else fi mdfile(){ + # Check if page exists, if possible fall + # back to default page from installation local page="$(PATH "$1")" if [ -f "$_DATA/pages/$page/#page.md" ]; then printf %s\\n "$_DATA/pages/$page/#page.md" + return 0 elif [ -f "$_EXEC/pages/$page/#page.md" ]; then printf %s\\n "$_EXEC/pages/$page/#page.md" + return 0 else return 1 - fi + fi 2>&- + # ^^ suppress error messages produced + # by printf when stdout was closed } size_human(){