Rebuild web caches immediately on ebook updates

This commit is contained in:
Alex Cabal 2022-07-14 15:28:57 -05:00
parent 60a58e9a95
commit e857e4e9e6
9 changed files with 115 additions and 70 deletions

View file

@ -143,6 +143,10 @@ if ! [ -f "${scriptsDir}"/generate-feeds ]; then
die "\"${scriptsDir}\"/generate-feeds\" is not a file or could not be found."
fi
if ! [ -f "${scriptsDir}"/generate-bulk-downloads ]; then
die "\"${scriptsDir}\"/generate-bulk-downloads\" is not a file or could not be found."
fi
mkdir -p "${webRoot}"/images/covers/
for dir in "$@"
@ -391,7 +395,7 @@ if [ "${queuedTasks}" = "false" ]; then
printf "Rebuilding web library cache ... "
fi
"${scriptsDir}"/rebuild-library-cache
"${scriptsDir}"/rebuild-cache library
if [ "${verbose}" = "true" ]; then
printf "Done.\n"
@ -410,6 +414,7 @@ if [ "${feeds}" = "true" ]; then
fi
"${scriptsDir}/generate-feeds" --webroot "${webRoot}" --weburl "${webUrl}"
"${scriptsDir}"/rebuild-cache feeds
if [ "${verbose}" = "true" ]; then
printf "Done.\n"
@ -429,6 +434,7 @@ if [ "${bulkDownloads}" = "true" ]; then
fi
"${scriptsDir}/generate-bulk-downloads" --webroot "${webRoot}"
"${scriptsDir}"/rebuild-cache bulk-downloads
if [ "${verbose}" = "true" ]; then
printf "Done.\n"

43
scripts/rebuild-cache Executable file
View file

@ -0,0 +1,43 @@
#!/bin/bash
usage(){
echo -n
fmt <<EOF
DESCRIPTION
Rebuild one of three caches stored in APCu for the standardebooks.org FPM pool.
USAGE
rebuild-cache {library,bulk-downloads,feeds}
EOF
exit 1
}
if [ $# -eq 1 ]; then
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage
fi
fi
if [ $# -ne 1 ]; then
usage
fi
# If this script is run by a user without sudo powers, they can be given permission to run this command by creating a file in sudoers.d with:
# MY_USERNAME ALL=(www-data) NOPASSWD: /usr/bin/env SCRIPT_FILENAME=/tmp/rebuild-cache.php REQUEST_METHOD=GET cgi-fcgi -bind -connect *
type="$1"
if [ "${type}" = "library" ]; then
echo "<?php require_once('Core.php'); Library::RebuildCache(); ?>" > /tmp/rebuild-cache.php
fi
if [ "${type}" = "bulk-downloads" ]; then
echo "<?php require_once('Core.php'); Library::RebuildBulkDownloadsCache(); ?>" > /tmp/rebuild-cache.php
fi
if [ "${type}" = "feeds" ]; then
echo "<?php require_once('Core.php'); Library::RebuildFeedsCache(); ?>" > /tmp/rebuild-cache.php
fi
sudo -u www-data env SCRIPT_FILENAME=/tmp/rebuild-cache.php REQUEST_METHOD=GET cgi-fcgi -bind -connect "/run/php/standardebooks.org.sock" &> /dev/null
rm /tmp/rebuild-cache.php

View file

@ -1,26 +0,0 @@
#!/bin/bash
usage(){
echo -n
fmt <<EOF
DESCRIPTION
Rebuild the library cache stored in APCu for the standardebooks.org FPM pool.
USAGE
rebuild-library-cache
EOF
exit 1
}
if [ $# -eq 1 ]; then
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage
fi
fi
# If this script is run by a user without sudo powers, they can be given for this command by creating a file in sudoers.d with:
# MY_USERNAME ALL=(www-data) NOPASSWD: /usr/bin/env SCRIPT_FILENAME=/tmp/rebuild-library-cache.php REQUEST_METHOD=GET cgi-fcgi -bind -connect *
echo "<?php require_once('Core.php'); Library::RebuildCache(); ?>" > /tmp/rebuild-library-cache.php
sudo -u www-data env SCRIPT_FILENAME=/tmp/rebuild-library-cache.php REQUEST_METHOD=GET cgi-fcgi -bind -connect "/run/php/standardebooks.org.sock" &> /dev/null
rm /tmp/rebuild-library-cache.php