admin: list accounts that have no active sessions
The Accounts tab (readStore.ListAccounts) inner-joined the authorizations aggregate, so any account with zero authorization rows was silently hidden - accounts that never finished login, had all sessions revoked, or were frozen then unfrozen. CountAccounts and SearchAccounts already LEFT JOIN, so the count and search disagreed with the list. Switch ListAccounts to LEFT JOIN auth and COALESCE the null last_active_at / device_count (sessionless accounts sort last), matching SearchAccounts.
This commit is contained in:
parent
686adc1e10
commit
c939f7c92e
2 changed files with 47 additions and 6 deletions
|
|
@ -837,18 +837,21 @@ WITH auth AS (
|
|||
SELECT u.id, u.phone, u.username, u.first_name, u.last_name, u.created_at, u.updated_at,
|
||||
COALESCE(r.frozen, false), COALESCE(r.reason, ''), u.verified, u.scam, u.fake,
|
||||
COALESCE(EXTRACT(EPOCH FROM u.premium_expires_at), 0)::bigint,
|
||||
auth.last_active_at, auth.device_count,
|
||||
COALESCE(auth.last_active_at, '0001-01-01 00:00:00+00'::timestamptz), COALESCE(auth.device_count, 0)::int,
|
||||
COALESCE(NULLIF(u.username, ''), p.username_lower, '') AS display_username,
|
||||
COALESCE(ap.login_email, ''),
|
||||
`+accountCollectibleUsernamesColumn+` AS collectibles
|
||||
FROM users u
|
||||
JOIN auth ON auth.user_id = u.id
|
||||
-- LEFT JOIN, not JOIN: an account with no authorizations (never finished login,
|
||||
-- all sessions revoked, frozen-then-unfrozen) must still appear here, matching
|
||||
-- CountAccounts and SearchAccounts.
|
||||
LEFT JOIN auth ON auth.user_id = u.id
|
||||
LEFT JOIN account_restrictions r ON r.user_id = u.id
|
||||
LEFT JOIN peer_usernames p ON p.peer_type = 'user' AND p.peer_id = u.id AND p.editable
|
||||
LEFT JOIN account_passwords ap ON ap.user_id = u.id
|
||||
WHERE NOT u.is_bot
|
||||
AND ($1::bigint = 0 OR (auth.last_active_at, u.id) < (to_timestamp(($1::double precision) / 1000000.0), $2::bigint))
|
||||
ORDER BY auth.last_active_at DESC, u.id DESC
|
||||
AND ($1::bigint = 0 OR (COALESCE(auth.last_active_at, '0001-01-01 00:00:00+00'::timestamptz), u.id) < (to_timestamp(($1::double precision) / 1000000.0), $2::bigint))
|
||||
ORDER BY COALESCE(auth.last_active_at, '0001-01-01 00:00:00+00'::timestamptz) DESC, u.id DESC
|
||||
LIMIT $3`, beforeActiveUS, beforeID, limit+1)
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("list accounts: %w", err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue