修复: 订单记录页opcache失效确保新版生效 + 订单查询放宽busy_timeout至15s并增加重试(规避database is locked)

This commit is contained in:
ypsdf1
2026-07-07 14:26:45 +08:00
parent a72bbfd970
commit 62f53234e7
2 changed files with 10 additions and 3 deletions
+6 -3
View File
@@ -160,6 +160,9 @@ function cashierOrderList() {
if (session_status() === PHP_SESSION_ACTIVE) session_write_close();
$db = getDB();
// ★ 订单是纯读查询:显式放宽 busy_timeout 让 SQLite 自身等待锁释放(WAL 下读不阻塞写),
// 大幅降低因 Java 高频写入导致的 "database is locked" 返回概率
$db->exec('PRAGMA busy_timeout=15000');
$limit = (int)getParam('limit', 100);
if ($limit <= 0 || $limit > 500) $limit = 100;
$sql = "SELECT * FROM cashier_orders";
@@ -170,10 +173,10 @@ function cashierOrderList() {
}
$sql .= " ORDER BY created_at DESC LIMIT " . (int)$limit;
// ★ 重试规避 database is locked(Java 高频写入时 SQLite 偶发锁,最多重试4次)
// ★ 重试规避 database is locked(Java 高频写入时 SQLite 偶发锁,最多重试5次,指数退避)
$rows = [];
$attempts = 0;
while ($attempts < 4) {
while ($attempts < 5) {
$attempts++;
$stmt = $db->prepare($sql);
if (!$stmt) break;
@@ -183,7 +186,7 @@ function cashierOrderList() {
$result = @$stmt->execute();
if ($result === false) {
$err = $db->lastErrorMsg();
if (stripos($err, 'locked') !== false && $attempts < 4) { usleep(200000); continue; }
if (stripos($err, 'locked') !== false && $attempts < 5) { usleep(200000 * $attempts); continue; }
exit(json_encode(['success' => false, 'message' => '查询失败: ' . $err], JSON_UNESCAPED_UNICODE));
}
while ($r = $result->fetchArray(SQLITE3_ASSOC)) {
+4
View File
@@ -5,6 +5,10 @@
*/
require_once __DIR__ . '/core.php';
// ★ 强制使 opcache 失效,确保部署后的新版(含请求超时/重试)立即生效,
// 避免 Web 服务端 opcache 持续服务旧版 orders.php(无超时→永久"加载中")
if (function_exists('opcache_invalidate')) { @opcache_invalidate(__FILE__); }
if (session_status() === PHP_SESSION_NONE) session_start();
$loggedIn = isAdminLoggedIn() || isCashierLoggedIn();