增加jump缓存的更新机制
This commit is contained in:
parent
ba215923ec
commit
7ee2576267
@ -3,6 +3,7 @@ import { role, router } from '../decorators/router'
|
||||
import { GameCache } from '../models/GameCache'
|
||||
import { getJumpGameInfo, getJumpGamePrice } from '../services/jump.svr'
|
||||
import { GamePriceCache } from '../models/GamePriceCache'
|
||||
const timeOut = 8 * 3600 * 1000
|
||||
|
||||
class GameProxyController extends BaseController {
|
||||
/**
|
||||
@ -14,7 +15,8 @@ class GameProxyController extends BaseController {
|
||||
let { accountId, oldGameId } = req.params
|
||||
oldGameId += ''
|
||||
let game = await GameCache.insertOrUpdate({ oldGameId }, {})
|
||||
if (game.inited) {
|
||||
let now = Date.now()
|
||||
if (now - game.lastupdate > timeOut) {
|
||||
try {
|
||||
let res = await getJumpGameInfo(oldGameId)
|
||||
if (res.success) {
|
||||
@ -23,7 +25,7 @@ class GameProxyController extends BaseController {
|
||||
game.dlcList = data.dlcList
|
||||
game.jumpGameExt = data.jumpGameExt
|
||||
game.otherPlatVersion = data.otherPlatVersion
|
||||
game.inited = false
|
||||
game.lastupdate = Date.now()
|
||||
await game.save()
|
||||
}
|
||||
} catch (err) {
|
||||
@ -43,7 +45,8 @@ class GameProxyController extends BaseController {
|
||||
nums = nums | 0 || 0
|
||||
oldGameId += ''
|
||||
let game = await GamePriceCache.insertOrUpdate({ oldGameId }, {})
|
||||
if (game.inited) {
|
||||
let now = Date.now()
|
||||
if (now - game.lastupdate > timeOut) {
|
||||
try {
|
||||
let res = await getJumpGamePrice(oldGameId)
|
||||
if (res.success) {
|
||||
|
@ -25,8 +25,9 @@ class GameCacheClass extends BaseModule {
|
||||
|
||||
@prop({ type: mongoose.Schema.Types.Mixed })
|
||||
public otherPlatVersion: any
|
||||
@prop({ default: true })
|
||||
public inited: boolean
|
||||
|
||||
@prop({ default: 0 })
|
||||
public lastupdate: number
|
||||
|
||||
public toJson(): any {
|
||||
let result: any = {}
|
||||
|
@ -17,8 +17,8 @@ class GamePriceCacheClass extends BaseModule {
|
||||
countries: any
|
||||
@prop({ type: mongoose.Schema.Types.Mixed })
|
||||
public prices: any
|
||||
@prop({ default: true })
|
||||
public inited: boolean
|
||||
@prop({ default: 0 })
|
||||
public lastupdate: number
|
||||
|
||||
public toJson(): any {
|
||||
let result: any = {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user