Skip to content

perf(stats): count all active-user windows in one query - #1235

Open
karlitschek wants to merge 1 commit into
masterfrom
perf/active-users-one-query
Open

karlitschek wants to merge 1 commit into
masterfrom
perf/active-users-one-query

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 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/active-users-one-query branch from 736435f to 9e3d6d8 Compare October 25, 2026 19:25
@nextcloud-command nextcloud-command added the AI assisted This PR contains AI-assisted commits label Oct 25, 2026
getSessionStatistics() ran one COUNT per time window, eight queries
that each cast configvalue over every login/lastLogin row of
oc_preferences. On an instance with a million users that is eight
million row reads per monitoring call.

Select the eight windows as SUM(CASE WHEN ... THEN 1 ELSE 0 END)
columns of a single query over the same rows. Each CASE uses the same
castColumn() comparison as before, so the counts match the old
per-window queries on every database, including the string and
non-numeric quirks of SQLite and MySQL. SUM over no rows is NULL and
maps to 0. The output keys, their order and the int values stay the
same.

The seen-users count in StorageStatistics already comes from
IUserManager::countSeenUsers(), a plain COUNT over the
(appid, configkey) index without a cast, so it stays as it is.

The tests compare the result with the old per-window queries, and cover
users exactly at and one second outside each cutoff, non-numeric and
empty values, no lastLogin rows at all, and the seen-users count.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Frank Karlitschek <karlitschek@users.noreply.github.com>
@karlitschek
karlitschek force-pushed the perf/active-users-one-query branch from 9e3d6d8 to fa3e347 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