diff --git a/src/controllers/gameproxy.controller.ts b/src/controllers/gameproxy.controller.ts index 4483244..e59802f 100644 --- a/src/controllers/gameproxy.controller.ts +++ b/src/controllers/gameproxy.controller.ts @@ -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) { diff --git a/src/models/GameCache.ts b/src/models/GameCache.ts index 3a2740f..6d610c8 100644 --- a/src/models/GameCache.ts +++ b/src/models/GameCache.ts @@ -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 = {} diff --git a/src/models/GamePriceCache.ts b/src/models/GamePriceCache.ts index ec740b7..625fdd9 100644 --- a/src/models/GamePriceCache.ts +++ b/src/models/GamePriceCache.ts @@ -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 = {}