Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
-- Migration: 20260601000001_matchmaking_perf_indexes
-- Description: Add composite indexes to matchmaking_queue to fix high-latency
-- queries that were doing full-table scans on (game, game_mode, status).
--
-- NOTE: matchmaking_queue.status is INTEGER (see 20240928000001_create_core_tables):
-- 0=waiting, 1=matched, 2=expired, 3=cancelled
-- Earlier revisions of this file used string literals ('waiting' / 'matched') in
-- the partial-index WHERE clauses, which fails with
-- ERROR: invalid input syntax for type integer: "waiting"
-- on PostgreSQL because the status column is INTEGER, not TEXT.

-- Composite index used by the background worker's active-game queries and by
-- the stats handler. Replaces the separate (status) and (game, game_mode)
Expand All @@ -16,7 +23,10 @@ CREATE INDEX IF NOT EXISTS idx_matchmaking_queue_waiting
WHERE status = 0;

-- Composite index for the average-wait-time aggregate query which filters on
-- (status = 1 (matched), matched_at IS NOT NULL, created_at >= ...).
-- (status = 1 (matched), matched_at IS NOT NULL, joined_at >= ...).
--
-- matchmaking_queue uses `joined_at` (not `created_at`) to record when a
-- player enters the queue — see 20240928000001_create_core_tables.
CREATE INDEX IF NOT EXISTS idx_matchmaking_queue_matched_stats
ON matchmaking_queue (game, game_mode, created_at)
ON matchmaking_queue (game, game_mode, joined_at)
WHERE status = 1 AND matched_at IS NOT NULL;
3 changes: 1 addition & 2 deletions backend/src/api_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ impl ApiError {
/// to API consumers — the public response always says "Internal server
/// error".
pub fn internal_error(message: impl Into<String>) -> Self {
ApiError::InternalServerError(message.into())
let msg = message.into();
error!(error.message = %msg, "Internal server error");
ApiError::InternalServerError
ApiError::InternalServerError(msg)
}

pub fn database_error(e: impl Into<sqlx::Error>) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/http/idempotency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::api_error::ApiError;
use crate::auth::Claims;
use crate::db::DbPool;
use crate::models::idempotency::*;
use crate::service::idempotency_service::{IdempotencyService, IdempotencyKeyResponse};
use crate::service::idempotency_service::{IdempotencyKeyRequest, IdempotencyKeyResponse, IdempotencyService};
use actix_web::{web, HttpResponse, Result};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
Expand Down
1 change: 1 addition & 0 deletions backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod db;
pub mod http;
pub mod middleware;
pub mod models;
pub mod orchestrator;
pub mod realtime;
pub mod service;
pub mod telemetry;
9 changes: 4 additions & 5 deletions backend/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ pub use match_models::{
ReportScoreRequest, UserElo,
};
pub use matchmaker::{
DisputeStatus, EloHistory, EloResponse, GameModeStats, GameQueueStats, JoinQueueRequest,
JoinQueueResponse, LeaveQueueRequest, LeaveQueueResponse, Match, MatchCandidate, MatchDispute,
MatchHistoryResponse, MatchmakingConfig, MatchmakingQueue, MatchmakingQueueResponse,
MatchmakingStats, MatchmakingStatsResponse, MatchmakingStatusResponse, MatchResult, MatchScore,
MatchStatus, MatchType, PlayerInfo, QueueEntry, QueueStatus, ReportScoreRequest, UserElo,
GameModeStats, GameQueueStats, JoinQueueRequest,
JoinQueueResponse, LeaveQueueRequest, LeaveQueueResponse, MatchCandidate,
MatchHistoryResponse, MatchmakingConfig, MatchmakingQueueResponse,
MatchmakingStats, QueueEntry,
};
pub use reward_settlement::*;
pub use stellar_account::{
Expand Down
Loading
Loading