List all active sessions for `SHOW SESSIONS`.
(&self)
| 326 | |
| 327 | /// List all active sessions for `SHOW SESSIONS`. |
| 328 | pub fn list_all(&self) -> Vec<SessionInfo> { |
| 329 | let now_s = now_secs(); |
| 330 | let sessions = self.sessions.read().unwrap_or_else(|p| p.into_inner()); |
| 331 | sessions |
| 332 | .iter() |
| 333 | .map(|(id, s)| { |
| 334 | let last_active = s.last_active.load(Ordering::Relaxed); |
| 335 | let token_expiry_ms = s.token_expiry_ms.load(Ordering::Relaxed); |
| 336 | let token_expires_in_seconds = if token_expiry_ms == 0 { |
| 337 | None |
| 338 | } else { |
| 339 | let exp_secs = token_expiry_ms / 1000; |
| 340 | Some(exp_secs.saturating_sub(now_s)) |
| 341 | }; |
| 342 | let digest = s |
| 343 | .current_statement_digest |
| 344 | .read() |
| 345 | .ok() |
| 346 | .and_then(|g| g.clone()); |
| 347 | SessionInfo { |
| 348 | session_id: id.clone(), |
| 349 | user_id: s.user_id, |
| 350 | db_user: s.db_user.clone(), |
| 351 | auth_method: s.auth_method.clone(), |
| 352 | connected_at: s.connected_at, |
| 353 | last_active, |
| 354 | client_ip: s.peer_addr.clone(), |
| 355 | protocol: s.protocol.clone(), |
| 356 | tenant_id: s.tenant_id, |
| 357 | credential_version: s.credential_version, |
| 358 | current_database: DatabaseId::new(s.current_database.load(Ordering::Relaxed)), |
| 359 | idle_seconds: now_s.saturating_sub(last_active), |
| 360 | bytes_in: s.bytes_in.load(Ordering::Relaxed), |
| 361 | bytes_out: s.bytes_out.load(Ordering::Relaxed), |
| 362 | current_statement_digest: digest, |
| 363 | token_expires_in_seconds, |
| 364 | } |
| 365 | }) |
| 366 | .collect() |
| 367 | } |
| 368 | |
| 369 | /// Returns the maximum session cap (0 = unlimited). |
| 370 | pub fn cap(&self) -> usize { |