mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
feat: update cdragon cache every 30min
This commit is contained in:
parent
d88d09d905
commit
d3125c4bb4
7 changed files with 69 additions and 17 deletions
|
|
@ -5,7 +5,8 @@
|
||||||
"@adonisjs/core/build/commands/index.js",
|
"@adonisjs/core/build/commands/index.js",
|
||||||
"@adonisjs/repl/build/commands",
|
"@adonisjs/repl/build/commands",
|
||||||
"@adonisjs/lucid/build/commands",
|
"@adonisjs/lucid/build/commands",
|
||||||
"@rocketseat/adonis-bull/build/commands"
|
"@rocketseat/adonis-bull/build/commands",
|
||||||
|
"@stouder-io/adonis-scheduler/build/commands/MakeTask"
|
||||||
],
|
],
|
||||||
"exceptionHandlerNamespace": "App/Exceptions/Handler",
|
"exceptionHandlerNamespace": "App/Exceptions/Handler",
|
||||||
"aliases": {
|
"aliases": {
|
||||||
|
|
@ -32,7 +33,8 @@
|
||||||
"@adonisjs/core",
|
"@adonisjs/core",
|
||||||
"@adonisjs/lucid",
|
"@adonisjs/lucid",
|
||||||
"@adonisjs/redis",
|
"@adonisjs/redis",
|
||||||
"@rocketseat/adonis-bull"
|
"@rocketseat/adonis-bull",
|
||||||
|
"@stouder-io/adonis-scheduler"
|
||||||
],
|
],
|
||||||
"aceProviders": [
|
"aceProviders": [
|
||||||
"@adonisjs/repl"
|
"@adonisjs/repl"
|
||||||
|
|
|
||||||
|
|
@ -649,6 +649,26 @@
|
||||||
"alias": "p"
|
"alias": "p"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"make:task": {
|
||||||
|
"settings": {
|
||||||
|
"loadApp": false,
|
||||||
|
"stayAlive": false
|
||||||
|
},
|
||||||
|
"commandPath": "@stouder-io/adonis-scheduler/build/commands/MakeTask",
|
||||||
|
"commandName": "make:task",
|
||||||
|
"description": "Make a new task",
|
||||||
|
"args": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"propertyName": "name",
|
||||||
|
"name": "name",
|
||||||
|
"required": true,
|
||||||
|
"description": "Name of the job class"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"aliases": [],
|
||||||
|
"flags": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"aliases": {}
|
"aliases": {}
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,10 @@ class CDragonService {
|
||||||
public readonly BASE_URL =
|
public readonly BASE_URL =
|
||||||
'https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/'
|
'https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/'
|
||||||
|
|
||||||
private setupCache<T extends Identifiable>(dto: T[]) {
|
private setupCache<T extends Identifiable>(key: string, dto: T[]) {
|
||||||
return dto.reduce((obj, item) => ((obj[item.id] = item), obj), {})
|
if (dto.length === 0) return
|
||||||
|
|
||||||
|
this[key] = dto.reduce((obj, item) => ((obj[item.id] = item), obj), {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -45,19 +47,23 @@ class CDragonService {
|
||||||
* Get global Context with CDragon Data
|
* Get global Context with CDragon Data
|
||||||
*/
|
*/
|
||||||
public async getContext() {
|
public async getContext() {
|
||||||
const items = await Jax.CDragon.items()
|
const [items, champions, perks, perkstyles, summonerSpells, championRoles] = await Promise.all([
|
||||||
const champions = await Jax.CDragon.champions()
|
Jax.CDragon.items(),
|
||||||
const perks = await Jax.CDragon.perks()
|
Jax.CDragon.champions(),
|
||||||
const perkstyles = await Jax.CDragon.perkstyles()
|
Jax.CDragon.perks(),
|
||||||
const summonerSpells = await Jax.CDragon.summonerSpells()
|
Jax.CDragon.perkstyles(),
|
||||||
const championRoles = await RoleIdentificationService.pullData().catch(() => {})
|
Jax.CDragon.summonerSpells(),
|
||||||
|
RoleIdentificationService.pullData().catch(() => {}),
|
||||||
|
])
|
||||||
|
|
||||||
this.champions = this.setupCache(champions)
|
this.setupCache('champions', champions)
|
||||||
this.items = this.setupCache(items)
|
this.setupCache('items', items)
|
||||||
this.perks = this.setupCache(perks)
|
this.setupCache('perks', perks)
|
||||||
this.perkstyles = this.setupCache(perkstyles.styles)
|
this.setupCache('perkstyles', perkstyles.styles)
|
||||||
this.summonerSpells = this.setupCache(summonerSpells)
|
this.setupCache('summonerSpells', summonerSpells)
|
||||||
this.championRoles = championRoles as ChampionsPlayRate
|
if (championRoles) {
|
||||||
|
this.championRoles = championRoles
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
11
server/app/Tasks/UpdateCDragonCache.ts
Normal file
11
server/app/Tasks/UpdateCDragonCache.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { TaskContract } from '@ioc:StouderIO/Scheduler'
|
||||||
|
import CDragonService from 'App/Services/CDragonService'
|
||||||
|
|
||||||
|
export default class UpdateCDragonCache implements TaskContract {
|
||||||
|
public readonly name: string = 'UpdateCDragonCache'
|
||||||
|
public readonly cron: string = '*/30 * * * *' // every 30 minutes
|
||||||
|
|
||||||
|
public async run(): Promise<void> {
|
||||||
|
await CDragonService.getContext()
|
||||||
|
}
|
||||||
|
}
|
||||||
11
server/package-lock.json
generated
11
server/package-lock.json
generated
|
|
@ -13,6 +13,7 @@
|
||||||
"@adonisjs/redis": "^7.3.4",
|
"@adonisjs/redis": "^7.3.4",
|
||||||
"@adonisjs/repl": "^3.1.11",
|
"@adonisjs/repl": "^3.1.11",
|
||||||
"@rocketseat/adonis-bull": "^1.0.4",
|
"@rocketseat/adonis-bull": "^1.0.4",
|
||||||
|
"@stouder-io/adonis-scheduler": "^1.0.3",
|
||||||
"got": "^11.8.5",
|
"got": "^11.8.5",
|
||||||
"luxon": "^3.4.3",
|
"luxon": "^3.4.3",
|
||||||
"pg": "^8.11.3",
|
"pg": "^8.11.3",
|
||||||
|
|
@ -1037,6 +1038,16 @@
|
||||||
"url": "https://github.com/sindresorhus/is?sponsor=1"
|
"url": "https://github.com/sindresorhus/is?sponsor=1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@stouder-io/adonis-scheduler": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@stouder-io/adonis-scheduler/-/adonis-scheduler-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-F1MTFU18HyBrh7ekNJoUhUMaUgzD89juIWbn2IQQieGYg7XnTVoRcbwS1zE5W8SFdrga2+w0+4EUidCdqiamVg==",
|
||||||
|
"dependencies": {
|
||||||
|
"@poppinss/utils": "^5.0.0",
|
||||||
|
"cron-parser": "^4.7.0",
|
||||||
|
"slash": "^3.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@szmarczak/http-timer": {
|
"node_modules/@szmarczak/http-timer": {
|
||||||
"version": "4.0.6",
|
"version": "4.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.6.tgz",
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@
|
||||||
"@adonisjs/redis": "^7.3.4",
|
"@adonisjs/redis": "^7.3.4",
|
||||||
"@adonisjs/repl": "^3.1.11",
|
"@adonisjs/repl": "^3.1.11",
|
||||||
"@rocketseat/adonis-bull": "^1.0.4",
|
"@rocketseat/adonis-bull": "^1.0.4",
|
||||||
|
"@stouder-io/adonis-scheduler": "^1.0.3",
|
||||||
"got": "^11.8.5",
|
"got": "^11.8.5",
|
||||||
"luxon": "^3.4.3",
|
"luxon": "^3.4.3",
|
||||||
"pg": "^8.11.3",
|
"pg": "^8.11.3",
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@
|
||||||
"@adonisjs/repl",
|
"@adonisjs/repl",
|
||||||
"@adonisjs/lucid",
|
"@adonisjs/lucid",
|
||||||
"@adonisjs/redis",
|
"@adonisjs/redis",
|
||||||
"@rocketseat/adonis-bull"
|
"@rocketseat/adonis-bull",
|
||||||
|
"@stouder-io/adonis-scheduler"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue