fix: revert RPCD optimizations that caused timeouts
Reverted to simpler, more stable implementation after optimizations caused XHR timeouts and module detection issues. Changes: - Removed opkg list caching that caused blocking issues - Simplified check_module_installed to avoid nested config_load - Added error handling (2>/dev/null || true) to prevent failures - Fixed awk command to handle errors gracefully This restores functionality while maintaining the core fixes: - Correct module detection with luci. prefix - Single config_load per request - Proper module listing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
a18ee87b28
commit
50b7612282
@ -25,27 +25,16 @@ detect_modules() {
|
|||||||
|
|
||||||
MODULES=$(detect_modules)
|
MODULES=$(detect_modules)
|
||||||
|
|
||||||
# Cache opkg list to avoid multiple calls
|
# Check if a module is installed (simple version)
|
||||||
OPKG_LIST=""
|
|
||||||
|
|
||||||
get_opkg_list() {
|
|
||||||
if [ -z "$OPKG_LIST" ]; then
|
|
||||||
OPKG_LIST=$(opkg list-installed 2>/dev/null)
|
|
||||||
fi
|
|
||||||
echo "$OPKG_LIST"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if a module is installed (optimized)
|
|
||||||
check_module_installed() {
|
check_module_installed() {
|
||||||
local module="$1"
|
local module="$1"
|
||||||
local package config
|
local package config
|
||||||
|
|
||||||
config_load secubox
|
|
||||||
config_get package "$module" package ""
|
config_get package "$module" package ""
|
||||||
config_get config "$module" config ""
|
config_get config "$module" config ""
|
||||||
|
|
||||||
# Check if package is installed via opkg (use cached list)
|
# Check if package is installed via opkg
|
||||||
if echo "$(get_opkg_list)" | grep -q "^${package} "; then
|
if opkg list-installed 2>/dev/null | grep -q "^${package} "; then
|
||||||
echo "1"
|
echo "1"
|
||||||
# Or check if config file exists
|
# Or check if config file exists
|
||||||
elif [ -f "/etc/config/${config}" ]; then
|
elif [ -f "/etc/config/${config}" ]; then
|
||||||
@ -585,16 +574,15 @@ quick_action() {
|
|||||||
json_dump
|
json_dump
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get all dashboard data in one call (optimized)
|
# Get all dashboard data in one call
|
||||||
get_dashboard_data() {
|
get_dashboard_data() {
|
||||||
json_init
|
json_init
|
||||||
|
|
||||||
# Get status info (cached reads)
|
# Get status info
|
||||||
local uptime=$(cat /proc/uptime | cut -d. -f1)
|
local uptime=$(cat /proc/uptime | cut -d. -f1)
|
||||||
local load=$(cat /proc/loadavg | cut -d' ' -f1-3)
|
local load=$(cat /proc/loadavg | cut -d' ' -f1-3)
|
||||||
local mem_info=$(grep -E "MemTotal|MemAvailable" /proc/meminfo)
|
local mem_total=$(grep MemTotal /proc/meminfo | awk '{print $2}')
|
||||||
local mem_total=$(echo "$mem_info" | grep MemTotal | awk '{print $2}')
|
local mem_free=$(grep MemAvailable /proc/meminfo | awk '{print $2}')
|
||||||
local mem_free=$(echo "$mem_info" | grep MemAvailable | awk '{print $2}')
|
|
||||||
local mem_used=$((mem_total - mem_free))
|
local mem_used=$((mem_total - mem_free))
|
||||||
local mem_pct=$((mem_used * 100 / mem_total))
|
local mem_pct=$((mem_used * 100 / mem_total))
|
||||||
|
|
||||||
@ -608,14 +596,13 @@ get_dashboard_data() {
|
|||||||
json_add_int "memory_percent" "$mem_pct"
|
json_add_int "memory_percent" "$mem_pct"
|
||||||
json_close_object
|
json_close_object
|
||||||
|
|
||||||
# Pre-load config once
|
# Load config once for all modules
|
||||||
config_load secubox
|
config_load secubox 2>/dev/null || true
|
||||||
|
|
||||||
# Cache module status checks
|
# Get modules list
|
||||||
|
json_add_array "modules"
|
||||||
local total=0 installed=0 running=0
|
local total=0 installed=0 running=0
|
||||||
|
|
||||||
# Get modules list (optimized - single loop)
|
|
||||||
json_add_array "modules"
|
|
||||||
for module in $MODULES; do
|
for module in $MODULES; do
|
||||||
local name desc category icon color
|
local name desc category icon color
|
||||||
config_get name "$module" name "$module"
|
config_get name "$module" name "$module"
|
||||||
@ -627,15 +614,14 @@ get_dashboard_data() {
|
|||||||
local is_installed=$(check_module_installed "$module")
|
local is_installed=$(check_module_installed "$module")
|
||||||
local is_running="0"
|
local is_running="0"
|
||||||
|
|
||||||
# Only check running status if installed
|
total=$((total + 1))
|
||||||
|
|
||||||
if [ "$is_installed" = "1" ]; then
|
if [ "$is_installed" = "1" ]; then
|
||||||
is_running=$(check_module_running "$module")
|
is_running=$(check_module_running "$module")
|
||||||
installed=$((installed + 1))
|
installed=$((installed + 1))
|
||||||
[ "$is_running" = "1" ] && running=$((running + 1))
|
[ "$is_running" = "1" ] && running=$((running + 1))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
total=$((total + 1))
|
|
||||||
|
|
||||||
json_add_object ""
|
json_add_object ""
|
||||||
json_add_string "id" "$module"
|
json_add_string "id" "$module"
|
||||||
json_add_string "name" "$name"
|
json_add_string "name" "$name"
|
||||||
@ -655,10 +641,10 @@ get_dashboard_data() {
|
|||||||
json_add_int "running" "$running"
|
json_add_int "running" "$running"
|
||||||
json_close_object
|
json_close_object
|
||||||
|
|
||||||
# Get system health (minimal computation)
|
# Get system health
|
||||||
local cpu_cores=$(grep -c processor /proc/cpuinfo)
|
local cpu_cores=$(grep -c processor /proc/cpuinfo)
|
||||||
local load_val=$(echo "$load" | cut -d' ' -f1)
|
local load_val=$(echo "$load" | cut -d' ' -f1)
|
||||||
local cpu_pct=$(awk "BEGIN {printf \"%.0f\", ($load_val / $cpu_cores) * 100}")
|
local cpu_pct=$(awk "BEGIN {printf \"%.0f\", ($load_val / $cpu_cores) * 100}" 2>/dev/null || echo "0")
|
||||||
local disk_pct=$(df / | tail -1 | awk '{print $5}' | tr -d '%')
|
local disk_pct=$(df / | tail -1 | awk '{print $5}' | tr -d '%')
|
||||||
|
|
||||||
json_add_object "health"
|
json_add_object "health"
|
||||||
@ -667,7 +653,7 @@ get_dashboard_data() {
|
|||||||
json_add_int "disk_percent" "$disk_pct"
|
json_add_int "disk_percent" "$disk_pct"
|
||||||
json_close_object
|
json_close_object
|
||||||
|
|
||||||
# Alerts - empty by default (fetched separately if needed)
|
# Empty alerts array
|
||||||
json_add_array "alerts"
|
json_add_array "alerts"
|
||||||
json_close_array
|
json_close_array
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user