Skip to content

Commit

Permalink
Simplified some queries
Browse files Browse the repository at this point in the history
  • Loading branch information
thordy committed Dec 11, 2024
1 parent a848eaf commit 1151efc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions data/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,8 @@ func GetHeadToHeadMatches(player1 int, player2 int) ([]*models.Match, error) {
JOIN match_type mt ON mt.id = m.match_type_id
JOIN match_mode mm ON mm.id = m.match_mode_id
JOIN player2leg p2l ON p2l.match_id = m.id
WHERE m.id IN (SELECT match_id FROM player2leg GROUP BY match_id HAVING COUNT(DISTINCT player_id) = 2)
JOIN leg l ON l.match_id = m.id
WHERE l.num_players = 2
AND m.is_finished = 1 AND m.is_abandoned = 0
AND m.match_type_id = 1
AND p2l.player_id IN (?, ?)
Expand Down Expand Up @@ -808,8 +809,9 @@ func GetPlayerLastMatches(playerID int, limit int) ([]*models.Match, error) {
JOIN match_type mt ON mt.id = m.match_type_id
JOIN match_mode mm ON mm.id = m.match_mode_id
JOIN player2leg p2l ON p2l.match_id = m.id
WHERE m.id IN (SELECT match_id FROM player2leg GROUP BY match_id HAVING COUNT(DISTINCT player_id) = 2)
AND m.is_finished = 1 AND m.is_abandoned = 0 AND m.is_practice = 0
JOIN leg l ON l.match_id = m.id
WHERE l.num_players = 2
AND m.is_finished = 1 AND m.is_abandoned = 0 AND m.is_practice = 0 AND m.is_bye = 0
AND p2l.player_id IN (?)
GROUP BY m.id
ORDER BY m.created_at DESC LIMIT ?`, playerID, limit)
Expand Down

0 comments on commit 1151efc

Please sign in to comment.