Skip to content

Commit 769597b

Browse files
committed
chore: improve performance for query matches and friends
1 parent b474bba commit 769597b

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

hasura/functions/players/get_player_matches.sql

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
CREATE OR REPLACE FUNCTION public.get_player_matches(player public.players) RETURNS SETOF public.matches
2-
LANGUAGE plpgsql STABLE
3-
AS $$
4-
DECLARE
5-
BEGIN
6-
RETURN QUERY
7-
SELECT DISTINCT m.*
8-
FROM match_lineup_players mlp
9-
INNER JOIN matches m ON (m.lineup_1_id = mlp.match_lineup_id OR m.lineup_2_id = mlp.match_lineup_id)
10-
WHERE mlp.steam_id = player.steam_id;
11-
END;
1+
CREATE OR REPLACE FUNCTION public.get_player_matches(player public.players)
2+
RETURNS SETOF public.matches
3+
LANGUAGE SQL STABLE
4+
AS $$
5+
SELECT DISTINCT m.*
6+
FROM match_lineup_players mlp
7+
JOIN matches m ON m.lineup_1_id = mlp.match_lineup_id
8+
WHERE mlp.steam_id = player.steam_id
9+
10+
UNION
11+
12+
SELECT DISTINCT m.*
13+
FROM match_lineup_players mlp
14+
JOIN matches m ON m.lineup_2_id = mlp.match_lineup_id
15+
WHERE mlp.steam_id = player.steam_id;
1216
$$;
1317

1418
CREATE OR REPLACE FUNCTION public.get_total_player_matches(player players)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_friends_other_player_steam_id
1+
CREATE INDEX IF NOT EXISTS idx_friends_other_player_steam_id
22
ON friends(other_player_steam_id, player_steam_id);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE INDEX IF NOT EXISTS idx_matches_created_at
2+
ON matches(created_at DESC);

0 commit comments

Comments
 (0)