From ac6c98bd35d32425608eaafe1cbf2efcd38a478a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Sun, 21 May 2023 11:56:56 +0200 Subject: [PATCH] speed improvement: save fork when checking mdfile existence --- handlers/20_page.sh | 2 +- handlers/90_brackets.sh | 2 +- themes/default.sh | 2 +- tools.sh | 8 +++++++- 4 files changed, 10 insertions(+), 4 deletions(-) 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(){ -- 2.39.2