Kuma/server
undaunt 2dc3e1ab1f Fix concurrent stat insertion duplicate key errors
This commit resolves duplicate key errors that occur when multiple monitors
attempt to insert statistics simultaneously into stat_* tables.

The fix addresses three interconnected issues:

1. **Circular Dependency Resolution**: database.js imports UptimeCalculator at
   module level, but UptimeCalculator needs Database.dbConfig. Fixed by using
   local imports in UptimeCalculator methods to ensure Database.dbConfig is
   properly initialized when accessed.

2. **Database Configuration Initialization**: Database.dbConfig was not set
   in the catch block when db-config.json is missing, causing undefined access
   errors. Fixed by ensuring Database.dbConfig is always set.

3. **Schema Column Naming Mismatch**: RedBean ORM uses camelCase (pingMin/pingMax)
   but Knex migrations create snake_case columns (ping_min/ping_max). Fixed by
   using correct snake_case column names in SQL queries.

4. **Atomic Upsert Operations**: Implemented database-specific upsert logic:
   - SQLite: INSERT ... ON CONFLICT DO UPDATE
   - MariaDB: INSERT ... ON DUPLICATE KEY UPDATE

The solution maintains backward compatibility by falling back to R.store()
when upsert fails, ensuring no data loss while eliminating race conditions
for users with many monitors (200+).

Fixes #5357
2025-06-17 22:41:41 -07:00
..
jobs Data migration and history retention for 2.0.0 (#5075) 2024-10-26 20:50:29 +08:00
model added option to force ipv4 or ipv6 for http(s) monitor type (#5880) 2025-06-13 08:14:55 +02:00
modules fix: Properly handle the NTLM part being embedded inside other authentication headers (#5871) 2025-06-13 15:08:11 +02:00
monitor-conditions Monitor Conditions (#5048) 2024-08-30 21:48:13 +02:00
monitor-types feat: Add a "manual" (static/fixed) monitor (#5897) 2025-06-13 13:38:49 +02:00
notification-providers ntfy.sh separate down priority (#5893) 2025-06-11 01:41:09 +02:00
routers Fix: [Push Monitor] Send notifications during maintenance period (#5847) 2025-05-20 12:38:21 +02:00
socket-handlers Fix (#5875) 2025-06-04 10:04:57 +08:00
utils Fix: Knex cannot set a default value for TEXT field (MariaDB) (#5261) 2024-10-28 13:16:22 +08:00
2fa.js Add JSDoc to server/* 2022-04-20 19:56:40 +01:00
auth.js Revert "feat: structured logging (JSON)" (#5175) 2024-10-09 07:43:44 +08:00
check-version.js Revert "feat: structured logging (JSON)" (#5175) 2024-10-09 07:43:44 +08:00
client.js Revert "feat: structured logging (JSON)" (#5175) 2024-10-09 07:43:44 +08:00
config.js Merge manually 2023-12-11 02:36:08 +08:00
database.js Fix concurrent stat insertion duplicate key errors 2025-06-17 22:41:41 -07:00
docker.js Made sure that more of the async usages are awaited (#4574) 2024-03-15 15:02:55 +01:00
embedded-mariadb.js Fix: Embedded MariaDB startup issue (#5283) 2024-11-05 20:25:08 +08:00
google-analytics.js Merge branch '1.23.X' into 1.23.X-merge-to-2.X.X-2 2023-11-25 03:25:03 +08:00
image-data-uri.js Added JSDoc to ESLint (#3529) 2023-08-11 15:46:41 +08:00
jobs.js Added JSDoc to ESLint (#3529) 2023-08-11 15:46:41 +08:00
notification.js feat: add notification provider Notifery (#5832) 2025-05-11 15:38:03 +02:00
password-hash.js Added JSDoc to ESLint (#3529) 2023-08-11 15:46:41 +08:00
prometheus.js Add monitor id label to prometheus metrics (#5907) 2025-06-12 12:31:01 +02:00
proxy.js chore(deps): upgrade http/https/socks proxy agents (#5548) 2025-01-26 14:21:40 +01:00
rate-limiter.js Added JSDoc to ESLint (#3529) 2023-08-11 15:46:41 +08:00
remote-browser.js 🐛 fix(remote-browser): Remove unused test() function (#4155) 2023-12-03 20:27:09 +08:00
server.js feat: Add a "manual" (static/fixed) monitor (#5897) 2025-06-13 13:38:49 +02:00
settings.js Added JSDoc to ESLint (#3529) 2023-08-11 15:46:41 +08:00
setup-database.js Fix UPTIME_KUMA_DB_NAME issue (#4169) 2023-12-05 05:16:55 +08:00
uptime-calculator.js Fix concurrent stat insertion duplicate key errors 2025-06-17 22:41:41 -07:00
uptime-kuma-server.js feat: Add a "manual" (static/fixed) monitor (#5897) 2025-06-13 13:38:49 +02:00
util-server.js Enhanced ping monitor with advanced options (count, timeout, numeric) (#5588) 2025-05-24 02:57:39 +02:00