mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
feat: add redis
This commit is contained in:
parent
7ab6db8ec2
commit
4fd79a5d84
7 changed files with 264 additions and 42 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
const Jax = use('Jax')
|
||||
const MatchService = use('App/Services/MatchService')
|
||||
const SummonerService = use('App/Services/SummonerService')
|
||||
const StatsService = use('App/Services/StatsService')
|
||||
const Summoner = use('App/Models/Summoner')
|
||||
|
||||
|
|
@ -41,12 +42,7 @@ class SummonerController {
|
|||
finalJSON.playing = !!currentGame
|
||||
|
||||
// RANKED STATS
|
||||
const ranked = await Jax.League.summonerID(account.id)
|
||||
finalJSON.ranked = {
|
||||
soloQ: ranked.find(e => e.queueType === 'RANKED_SOLO_5x5') || null,
|
||||
flex5v5: ranked.find(e => e.queueType === 'RANKED_FLEX_SR') || null,
|
||||
flex3v3: ranked.find(e => e.queueType === 'RANKED_FLEX_TT') || null
|
||||
}
|
||||
finalJSON.ranked = await SummonerService.getRanked(account)
|
||||
|
||||
// MATCH LIST
|
||||
await MatchService.updateMatchList(account, summonerDB)
|
||||
|
|
|
|||
25
server/app/Services/SummonerService.js
Normal file
25
server/app/Services/SummonerService.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
'use strict'
|
||||
|
||||
const Jax = use('Jax')
|
||||
const Redis = use('Redis')
|
||||
|
||||
class SummonerService {
|
||||
async getRanked(account) {
|
||||
const rankedCache = await Redis.get(`ranked-${account.puuid}`)
|
||||
if (rankedCache) {
|
||||
console.log('RANKED CACHED')
|
||||
return JSON.parse(rankedCache)
|
||||
} else {
|
||||
const ranked = await Jax.League.summonerID(account.id)
|
||||
const result = {
|
||||
soloQ: ranked.find(e => e.queueType === 'RANKED_SOLO_5x5') || null,
|
||||
flex5v5: ranked.find(e => e.queueType === 'RANKED_FLEX_SR') || null,
|
||||
flex3v3: ranked.find(e => e.queueType === 'RANKED_FLEX_TT') || null
|
||||
}
|
||||
await Redis.set(`ranked-${account.puuid}`, JSON.stringify(result), 'EX', 10)
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new SummonerService()
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
/*
|
||||
* When enabled, Bulblebee will automatically parse the ?include=
|
||||
* parameter and include all requested resources
|
||||
*/
|
||||
parseRequest: false,
|
||||
|
||||
/*
|
||||
* Nested includes will be resolved up to this limit any further nested
|
||||
* resources are going to be ignored
|
||||
*/
|
||||
includeRecursionLimit: 10,
|
||||
|
||||
/*
|
||||
* The serializer will be used to transform the data into its final
|
||||
* representation.
|
||||
* Currently supported: 'plain', 'data'
|
||||
*/
|
||||
serializer: 'plain',
|
||||
|
||||
/*
|
||||
* When a transformer is reffered to by its name only, Bumblebee will try to
|
||||
* resolve the transformer using this namespace as prefix.
|
||||
*/
|
||||
namespace: 'App/Transformers'
|
||||
}
|
||||
64
server/config/redis.js
Normal file
64
server/config/redis.js
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
'use strict'
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Redis Configuaration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here we define the configuration for redis server. A single application
|
||||
| can make use of multiple redis connections using the redis provider.
|
||||
|
|
||||
*/
|
||||
|
||||
const Env = use('Env')
|
||||
|
||||
module.exports = {
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| connection
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Redis connection to be used by default.
|
||||
|
|
||||
*/
|
||||
connection: Env.get('REDIS_CONNECTION', 'local'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| local connection config
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Configuration for a named connection.
|
||||
|
|
||||
*/
|
||||
local: {
|
||||
host: '127.0.0.1',
|
||||
port: 6379,
|
||||
password: null,
|
||||
db: 0,
|
||||
keyPrefix: ''
|
||||
},
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| cluster config
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Below is the configuration for the redis cluster.
|
||||
|
|
||||
*/
|
||||
cluster: {
|
||||
clusters: [{
|
||||
host: '127.0.0.1',
|
||||
port: 6379,
|
||||
password: null,
|
||||
db: 0
|
||||
},
|
||||
{
|
||||
host: '127.0.0.1',
|
||||
port: 6380,
|
||||
password: null,
|
||||
db: 0
|
||||
}]
|
||||
}
|
||||
}
|
||||
176
server/package-lock.json
generated
176
server/package-lock.json
generated
|
|
@ -174,6 +174,27 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"@adonisjs/redis": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@adonisjs/redis/-/redis-2.0.7.tgz",
|
||||
"integrity": "sha512-2wnZKZU/pB2HiwQP2HW/68t5XdB7aRvyFLMVDKPdPPmcbZcVXZH19RWkRs91eTnYzsC14PzUf471FsUkT93lBg==",
|
||||
"requires": {
|
||||
"@adonisjs/generic-exceptions": "^2.0.1",
|
||||
"debug": "^3.1.0",
|
||||
"ioredis": "^3.2.2",
|
||||
"lodash": "^4.17.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "3.2.6",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
|
||||
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
|
||||
"requires": {
|
||||
"ms": "^2.1.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@sindresorhus/is": {
|
||||
"version": "0.14.0",
|
||||
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz",
|
||||
|
|
@ -216,11 +237,6 @@
|
|||
"resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-7.0.0.tgz",
|
||||
"integrity": "sha512-7Bv1We7ZGuU79zZbb6rRqcpxo3OY+zrdtloZWoyD8fmGX+FeXRjE+iuGkZjSXLVovLzrsvMGMy0EkwA0E0umxg=="
|
||||
},
|
||||
"adonis-bumblebee": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/adonis-bumblebee/-/adonis-bumblebee-2.0.0.tgz",
|
||||
"integrity": "sha512-HUvzuoU3Xb4je23Pjec1SLTA8r8GWUoE6BVCl9y32IfrqKD3o1XXWwWcHs5SK1zFgb4OLjB6NDWQmvg8MKs1tg=="
|
||||
},
|
||||
"ajv": {
|
||||
"version": "6.10.2",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.2.tgz",
|
||||
|
|
@ -904,6 +920,11 @@
|
|||
"mimic-response": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"cluster-key-slot": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.0.tgz",
|
||||
"integrity": "sha512-2Nii8p3RwAPiFwsnZvukotvow2rIHM+yQ6ZcBXGHdniadkYGZYiGmkHJIbZPIV9nfv7m/U1IPMVVcAhoWFeklw=="
|
||||
},
|
||||
"co-body": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/co-body/-/co-body-6.0.0.tgz",
|
||||
|
|
@ -1110,6 +1131,11 @@
|
|||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
|
||||
},
|
||||
"denque": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz",
|
||||
"integrity": "sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ=="
|
||||
},
|
||||
"depd": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
|
||||
|
|
@ -1517,6 +1543,11 @@
|
|||
"resolved": "https://registry.npmjs.org/flagged-respawn/-/flagged-respawn-1.0.1.tgz",
|
||||
"integrity": "sha512-lNaHNVymajmk0OJMBn8fVUAU1BtDeKIqKoVhk4xAALB57aALg6b4W0MfJ/cUE0g9YBXy5XhSlPIpYIJ7HaY/3Q=="
|
||||
},
|
||||
"flexbuffer": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/flexbuffer/-/flexbuffer-0.0.6.tgz",
|
||||
"integrity": "sha1-A5/fI/iCPkQMOPMnfm/vEXQhWzA="
|
||||
},
|
||||
"for-in": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
|
||||
|
|
@ -1798,6 +1829,51 @@
|
|||
"resolved": "https://registry.npmjs.org/interpret/-/interpret-1.2.0.tgz",
|
||||
"integrity": "sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw=="
|
||||
},
|
||||
"ioredis": {
|
||||
"version": "3.2.2",
|
||||
"resolved": "https://registry.npmjs.org/ioredis/-/ioredis-3.2.2.tgz",
|
||||
"integrity": "sha512-g+ShTQYLsCcOUkNOK6CCEZbj3aRDVPw3WOwXk+LxlUKvuS9ujEqP2MppBHyRVYrNNFW/vcPaTBUZ2ctGNSiOCA==",
|
||||
"requires": {
|
||||
"bluebird": "^3.3.4",
|
||||
"cluster-key-slot": "^1.0.6",
|
||||
"debug": "^2.6.9",
|
||||
"denque": "^1.1.0",
|
||||
"flexbuffer": "0.0.6",
|
||||
"lodash.assign": "^4.2.0",
|
||||
"lodash.bind": "^4.2.1",
|
||||
"lodash.clone": "^4.5.0",
|
||||
"lodash.clonedeep": "^4.5.0",
|
||||
"lodash.defaults": "^4.2.0",
|
||||
"lodash.difference": "^4.5.0",
|
||||
"lodash.flatten": "^4.4.0",
|
||||
"lodash.foreach": "^4.5.0",
|
||||
"lodash.isempty": "^4.4.0",
|
||||
"lodash.keys": "^4.2.0",
|
||||
"lodash.noop": "^3.0.1",
|
||||
"lodash.partial": "^4.2.1",
|
||||
"lodash.pick": "^4.4.0",
|
||||
"lodash.sample": "^4.2.1",
|
||||
"lodash.shuffle": "^4.2.0",
|
||||
"lodash.values": "^4.3.0",
|
||||
"redis-commands": "^1.2.0",
|
||||
"redis-parser": "^2.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
}
|
||||
}
|
||||
},
|
||||
"ipaddr.js": {
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz",
|
||||
|
|
@ -2186,6 +2262,46 @@
|
|||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
||||
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
|
||||
},
|
||||
"lodash.assign": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz",
|
||||
"integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc="
|
||||
},
|
||||
"lodash.bind": {
|
||||
"version": "4.2.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.bind/-/lodash.bind-4.2.1.tgz",
|
||||
"integrity": "sha1-euMBfpOWIqwxt9fX3LGzTbFpDTU="
|
||||
},
|
||||
"lodash.clone": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.clone/-/lodash.clone-4.5.0.tgz",
|
||||
"integrity": "sha1-GVhwRQ9aExkkeN9Lw9I9LeoZB7Y="
|
||||
},
|
||||
"lodash.clonedeep": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
||||
"integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8="
|
||||
},
|
||||
"lodash.defaults": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz",
|
||||
"integrity": "sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw="
|
||||
},
|
||||
"lodash.difference": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.difference/-/lodash.difference-4.5.0.tgz",
|
||||
"integrity": "sha1-nMtOUF1Ia5FlE0V3KIWi3yf9AXw="
|
||||
},
|
||||
"lodash.flatten": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz",
|
||||
"integrity": "sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8="
|
||||
},
|
||||
"lodash.foreach": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.foreach/-/lodash.foreach-4.5.0.tgz",
|
||||
"integrity": "sha1-Gmo16s5AEoDH8G3d7DUWWrJ+PlM="
|
||||
},
|
||||
"lodash.includes": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
|
||||
|
|
@ -2196,6 +2312,11 @@
|
|||
"resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz",
|
||||
"integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY="
|
||||
},
|
||||
"lodash.isempty": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isempty/-/lodash.isempty-4.4.0.tgz",
|
||||
"integrity": "sha1-b4bL7di+TsmHvpqvM8loTbGzHn4="
|
||||
},
|
||||
"lodash.isinteger": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz",
|
||||
|
|
@ -2216,11 +2337,46 @@
|
|||
"resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz",
|
||||
"integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE="
|
||||
},
|
||||
"lodash.keys": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-4.2.0.tgz",
|
||||
"integrity": "sha1-oIYCrBLk+4P5H8H7ejYKTZujUgU="
|
||||
},
|
||||
"lodash.noop": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.noop/-/lodash.noop-3.0.1.tgz",
|
||||
"integrity": "sha1-OBiPTWUKOkdCWEObluxFsyYXEzw="
|
||||
},
|
||||
"lodash.once": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz",
|
||||
"integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w="
|
||||
},
|
||||
"lodash.partial": {
|
||||
"version": "4.2.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.partial/-/lodash.partial-4.2.1.tgz",
|
||||
"integrity": "sha1-SfPYz9qjv/izqR0SfpIyRUGJYdQ="
|
||||
},
|
||||
"lodash.pick": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.pick/-/lodash.pick-4.4.0.tgz",
|
||||
"integrity": "sha1-UvBWEP/53tQiYRRB7R/BI6AwAbM="
|
||||
},
|
||||
"lodash.sample": {
|
||||
"version": "4.2.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.sample/-/lodash.sample-4.2.1.tgz",
|
||||
"integrity": "sha1-XkKRsMdT+hq+sKq4+ynfG2bwf20="
|
||||
},
|
||||
"lodash.shuffle": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.shuffle/-/lodash.shuffle-4.2.0.tgz",
|
||||
"integrity": "sha1-FFtQU8+HX29cKjP0i26ZSMbse0s="
|
||||
},
|
||||
"lodash.values": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.values/-/lodash.values-4.3.0.tgz",
|
||||
"integrity": "sha1-o6bCsOvsxcLLocF+bmIP6BtT00c="
|
||||
},
|
||||
"log-ok": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/log-ok/-/log-ok-0.1.1.tgz",
|
||||
|
|
@ -3603,6 +3759,16 @@
|
|||
"resolve": "^1.1.6"
|
||||
}
|
||||
},
|
||||
"redis-commands": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.5.0.tgz",
|
||||
"integrity": "sha512-6KxamqpZ468MeQC3bkWmCB1fp56XL64D4Kf0zJSwDZbVLLm7KFkoIcHrgRvQ+sk8dnhySs7+yBg94yIkAK7aJg=="
|
||||
},
|
||||
"redis-parser": {
|
||||
"version": "2.6.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-2.6.0.tgz",
|
||||
"integrity": "sha1-Uu0J2srBCPGmMcB+m2mUHnoZUEs="
|
||||
},
|
||||
"regenerator-runtime": {
|
||||
"version": "0.11.1",
|
||||
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz",
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
"@adonisjs/framework": "^5.0.9",
|
||||
"@adonisjs/ignitor": "^2.0.8",
|
||||
"@adonisjs/lucid": "^6.1.3",
|
||||
"adonis-bumblebee": "^2.0.0",
|
||||
"@adonisjs/redis": "^2.0.7",
|
||||
"got": "^9.6.0",
|
||||
"lucid-mongo": "^3.1.6",
|
||||
"mongodb-core": "^3.2.7",
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ const providers = [
|
|||
'@adonisjs/bodyparser/providers/BodyParserProvider',
|
||||
'@adonisjs/cors/providers/CorsProvider',
|
||||
'lucid-mongo/providers/LucidMongoProvider',
|
||||
'adonis-bumblebee/providers/BumblebeeProvider',
|
||||
'@adonisjs/redis/providers/RedisProvider',
|
||||
|
||||
join(__dirname, '../providers/Jax/JaxProvider')
|
||||
]
|
||||
|
|
@ -33,7 +33,6 @@ const providers = [
|
|||
*/
|
||||
const aceProviders = [
|
||||
'lucid-mongo/providers/MigrationsProvider',
|
||||
'adonis-bumblebee/providers/CommandsProvider'
|
||||
]
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in a new issue