Skip to content

perf(api): cache the database statistics for the monitoring api and the page - #1233

Open
karlitschek wants to merge 1 commit into
masterfrom
perf/api-statistics-cache
Open

karlitschek wants to merge 1 commit into
masterfrom
perf/api-statistics-cache

Conversation

@karlitschek

Copy link
Copy Markdown
Member

Based on feat/os-status-collector (#1214).

AI disclosure: this change was written with Claude Code (claude-opus-5-5) and is to be reviewed by the author before it leaves draft; every commit carries an Assisted-by trailer.

🤖 Generated with Claude Code

@karlitschek
karlitschek force-pushed the feat/os-status-collector branch 2 times, most recently from 6d327c2 to 34014ec Compare October 25, 2026 19:19
Base automatically changed from feat/os-status-collector to master October 25, 2026 19:24
@karlitschek
karlitschek force-pushed the perf/api-statistics-cache branch from 0d7e87b to 3f289d1 Compare October 25, 2026 19:25
@nextcloud-command nextcloud-command added the AI assisted This PR contains AI-assisted commits label Oct 25, 2026
The OCS info endpoint and the admin page's /data each ran about 25
database queries on every call: storage and user counts, ten share
counts, eight active-user windows, and the database version and size,
which on MySQL is SHOW TABLE STATUS and on PostgreSQL
pg_database_size(). Monitoring systems scrape the endpoint every 15 to
60 seconds, so these queries ran thousands of times a day for values
that change on a scale of minutes.

StatisticsCache computes that block once and keeps it in the
distributed cache under one key, which both callers read, so they never
compute it twice. The block is stored as JSON with zero fractions
preserved, so a float such as size_appdata_storage keeps its type on
the Redis backend too and callers get exactly what a fresh computation
returns. The lifetime comes from the new app config key
statistics_cache_ttl: 300 seconds by default, clamped to 0..3600, with
0 turning the cache off.

CPU, memory, PHP, PHP-FPM, OPcache and the web server stay live. The
skipApps, skipUpdate and skipOs parts are outside the cached block and
keep their own behaviour, so the cache needs no per-parameter keys. The
statistics queries themselves are unchanged.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Frank Karlitschek <[email protected]>
@karlitschek
karlitschek force-pushed the perf/api-statistics-cache branch from 3f289d1 to 8ff02b5 Compare October 25, 2026 19:45
@karlitschek
karlitschek marked this pull request as ready for review October 25, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI assisted This PR contains AI-assisted commits

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants