diff --git a/server/app/Repositories/MatchRepository.ts b/server/app/Repositories/MatchRepository.ts index 2a12fc7..8f5613d 100644 --- a/server/app/Repositories/MatchRepository.ts +++ b/server/app/Repositories/MatchRepository.ts @@ -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) diff --git a/server/app/Services/MatchService.ts b/server/app/Services/MatchService.ts index 88b0dae..2c1df27 100644 --- a/server/app/Services/MatchService.ts +++ b/server/app/Services/MatchService.ts @@ -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) diff --git a/server/database/migrations/1705237182688_matchlist_add_useful_fields.ts b/server/database/migrations/1705237182688_matchlist_add_useful_fields.ts new file mode 100644 index 0000000..a784187 --- /dev/null +++ b/server/database/migrations/1705237182688_matchlist_add_useful_fields.ts @@ -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') + }) + } +}