mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
feat: flag useless matchlist ids in DB to prevent fetching
This commit is contained in:
parent
46b47fced5
commit
a900b108d5
3 changed files with 34 additions and 3 deletions
|
|
@ -36,6 +36,7 @@ class MatchRepository {
|
|||
const matchListQuery = SummonerMatchlist.query()
|
||||
.select('matchId')
|
||||
.where('summoner_puuid', filters.puuid)
|
||||
.andWhere('useful', true)
|
||||
|
||||
if (filters.lastMatchId) {
|
||||
matchListQuery.andWhere('match_id', '<', filters.lastMatchId)
|
||||
|
|
|
|||
|
|
@ -129,15 +129,28 @@ class MatchService {
|
|||
|
||||
/* If we have to store some matches in the db */
|
||||
if (matchesFromApi.length !== 0) {
|
||||
const matchIdsNotUseful: string[] = []
|
||||
// Remove bugged matches from the Riot API + tutorial games
|
||||
const filteredMatches = matchesFromApi.filter(notEmpty).filter(
|
||||
(m) =>
|
||||
const filteredMatches = matchesFromApi.filter(notEmpty).filter((m) => {
|
||||
const toKeep =
|
||||
!tutorialQueues.includes(m.info.queueId) &&
|
||||
m.info.teams.length > 0 &&
|
||||
m.info.participants.length > 0 &&
|
||||
m.info.gameMode !== 'PRACTICETOOL' &&
|
||||
m.info.gameMode !== 'CHERRY' // Arena mode
|
||||
)
|
||||
|
||||
if (!toKeep) {
|
||||
matchIdsNotUseful.push(m.metadata.matchId)
|
||||
}
|
||||
return toKeep
|
||||
})
|
||||
|
||||
// Flag match ids in matchlist that are not useful (to not fetch them again)
|
||||
if (matchIdsNotUseful.length) {
|
||||
await Database.from('summoner_matchlist')
|
||||
.whereIn('match_id', matchIdsNotUseful)
|
||||
.update({ useful: false })
|
||||
}
|
||||
|
||||
// Transform raw matches data
|
||||
const parsedMatches: any = await MatchParser.parse(filteredMatches)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
|
||||
|
||||
export default class extends BaseSchema {
|
||||
protected tableName = 'summoner_matchlist'
|
||||
|
||||
public async up() {
|
||||
this.schema.alterTable(this.tableName, (table) => {
|
||||
table.boolean('useful').defaultTo(true).notNullable().index()
|
||||
})
|
||||
}
|
||||
|
||||
public async down() {
|
||||
this.schema.alterTable(this.tableName, (table) => {
|
||||
table.dropColumn('useful')
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue