From 10278b55fbffeadf8237a1221d8c286585aca1a1 Mon Sep 17 00:00:00 2001 From: klarkxy <278370456@qq.com> Date: Fri, 13 Mar 2026 15:16:29 +0800 Subject: [PATCH] feat: add automatic git pull on homepage visit with rate limiting Introduce a mechanism to automatically pull the latest changes from the git repository when the homepage is accessed. This ensures the application stays up-to-date without manual intervention. The feature includes a lock file (`/tmp/hustoj_git_pull.lock`) to prevent excessive pulls, limiting execution to at most once every 60 seconds. The git pull command runs in the background to avoid blocking the page load, with output logged to `/tmp/hustoj_git_pull.log`. --- web/index.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/web/index.php b/web/index.php index 91a426f..a1f5ccf 100644 --- a/web/index.php +++ b/web/index.php @@ -2,6 +2,15 @@ ////////////////////////////Common head $cache_time = 30; $OJ_CACHE_SHARE = false; + +// Auto git pull on homepage visit (at most once per 60 seconds) +$git_pull_lock = '/tmp/hustoj_git_pull.lock'; +if (!file_exists($git_pull_lock) || (time() - filemtime($git_pull_lock)) > 60) { + touch($git_pull_lock); + $repo_dir = dirname(__DIR__); + exec("cd " . escapeshellarg($repo_dir) . " && git pull > /tmp/hustoj_git_pull.log 2>&1 &"); +} + require_once( './include/cache_start.php' ); require_once( './include/db_info.inc.php' ); require_once( './include/memcache.php' );