mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
refactor: clean some code for MatchList results
This commit is contained in:
parent
ba8c05fbe8
commit
ac00801d9f
2 changed files with 21 additions and 15 deletions
|
|
@ -48,12 +48,11 @@ class SummonerController {
|
||||||
const soloQ = ranked.filter(e => e.queueType === 'RANKED_SOLO_5x5')
|
const soloQ = ranked.filter(e => e.queueType === 'RANKED_SOLO_5x5')
|
||||||
finalJSON.soloQ = soloQ.length ? soloQ[0] : null;
|
finalJSON.soloQ = soloQ.length ? soloQ[0] : null;
|
||||||
|
|
||||||
console.time('getMatches')
|
|
||||||
|
|
||||||
// MATCH LIST
|
// MATCH LIST
|
||||||
const matchList = await MatchHelper.getFullMatchList(account)
|
const matchList = await MatchHelper.getFullMatchList(account)
|
||||||
|
|
||||||
// MATCHES DETAILS
|
// MATCHES DETAILS
|
||||||
|
console.time('getMatches')
|
||||||
const gameIds = matchList.slice(0, 10).map(({ gameId }) => gameId)
|
const gameIds = matchList.slice(0, 10).map(({ gameId }) => gameId)
|
||||||
|
|
||||||
let matchesDetails = []
|
let matchesDetails = []
|
||||||
|
|
|
||||||
|
|
@ -31,33 +31,40 @@ class MatchHelper {
|
||||||
* @param account of the summoner
|
* @param account of the summoner
|
||||||
*/
|
*/
|
||||||
async getFullMatchList(account) {
|
async getFullMatchList(account) {
|
||||||
|
console.time('matchList')
|
||||||
const today = Date.now()
|
const today = Date.now()
|
||||||
let matches
|
let matchList = []
|
||||||
|
|
||||||
let summonerDB = await Summoner.where({ puuid: account.puuid }).first()
|
let summonerDB = await Summoner.where({ puuid: account.puuid }).first()
|
||||||
// Summoner has already been searched : we already have a MatchList and we need to update it
|
// Summoner has already been searched : we already have a MatchList and we need to update it
|
||||||
if (summonerDB) {
|
if (summonerDB) {
|
||||||
matches = (await Jax.Matchlist.accountID(account.accountId, 0)).matches
|
let alreadyIn = false
|
||||||
let alreadyIn = summonerDB.matchList.some(m => m.gameId === matches[matches.length - 1].gameId)
|
let index = 0
|
||||||
let index = 100
|
do {
|
||||||
while (!alreadyIn) {
|
|
||||||
let newMatchList = (await Jax.Matchlist.accountID(account.accountId, index)).matches
|
let newMatchList = (await Jax.Matchlist.accountID(account.accountId, index)).matches
|
||||||
matches = [...matches, ...newMatchList]
|
|
||||||
alreadyIn = summonerDB.matchList.some(m => m.gameId === matches[matches.length - 1].gameId)
|
|
||||||
index += 100
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update Summoner
|
matchList = [...matchList, ...newMatchList]
|
||||||
summonerDB.matchList = [...new Set([...summonerDB.matchList, ...matches])]
|
alreadyIn = summonerDB.matchList.some(m => m.gameId === matchList[matchList.length - 1].gameId)
|
||||||
|
index += 100
|
||||||
|
} while (!alreadyIn);
|
||||||
|
|
||||||
|
// Update Summoner's MatchList
|
||||||
|
for (const match of matchList) {
|
||||||
|
if (!summonerDB.matchList.some(m => m.gameId === match.gameId)) {
|
||||||
|
Logger.transport('file').info(`Match ${match.gameId} has been added to ${account.name}'s MatchList.`)
|
||||||
|
summonerDB.matchList.push(match)
|
||||||
|
}
|
||||||
|
}
|
||||||
await summonerDB.save()
|
await summonerDB.save()
|
||||||
Logger.transport('file').info(`Summoner ${account.name} has been updated.`)
|
Logger.transport('file').info(`Summoner ${account.name} has been updated.`)
|
||||||
}
|
}
|
||||||
// First search of the Summoner
|
// First search of the Summoner
|
||||||
else {
|
else {
|
||||||
matches = await this.getMatchListFourMonths(today, account.accountId, 0, [])
|
matchList = await this.getMatchListFourMonths(today, account.accountId, 0, [])
|
||||||
summonerDB = await Summoner.create({ puuid: account.puuid, matchList: matches })
|
summonerDB = await Summoner.create({ puuid: account.puuid, matchList: matchList })
|
||||||
Logger.transport('file').info(`Summoner ${account.name} has been created.`)
|
Logger.transport('file').info(`Summoner ${account.name} has been created.`)
|
||||||
}
|
}
|
||||||
|
console.timeEnd('matchList')
|
||||||
|
|
||||||
return summonerDB.matchList
|
return summonerDB.matchList
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue