mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
refactor: records SQL query 50 times faster
This commit is contained in:
parent
618b7b3992
commit
b17a80b2af
1 changed files with 31 additions and 17 deletions
|
|
@ -309,12 +309,11 @@ class MatchRepository {
|
|||
'match_players.penta_kills',
|
||||
]
|
||||
|
||||
const query = fields
|
||||
.map((field) => {
|
||||
return `
|
||||
(SELECT
|
||||
'${field}' AS what,
|
||||
${field} AS amount,
|
||||
const query =
|
||||
`
|
||||
WITH base as (
|
||||
SELECT
|
||||
${fields.join()},
|
||||
match_players.win as result,
|
||||
matches.id,
|
||||
matches.date,
|
||||
|
|
@ -325,12 +324,27 @@ class MatchRepository {
|
|||
${this.JOIN_MATCHES}
|
||||
WHERE
|
||||
${this.globalFilters(filters)}
|
||||
)
|
||||
` +
|
||||
fields
|
||||
.map(
|
||||
(field) => `
|
||||
(SELECT
|
||||
'${field}' AS what,
|
||||
${field.split('.').pop()} AS amount,
|
||||
result,
|
||||
id,
|
||||
date,
|
||||
gamemode,
|
||||
champion_id
|
||||
FROM
|
||||
base
|
||||
ORDER BY
|
||||
${field} DESC, matches.id
|
||||
2 DESC, id
|
||||
LIMIT
|
||||
1)
|
||||
`
|
||||
})
|
||||
)
|
||||
.join(' UNION ALL ')
|
||||
|
||||
const { rows } = await Database.rawQuery(query, filters as any)
|
||||
|
|
|
|||
Loading…
Reference in a new issue