增加jump缓存的更新机制

This commit is contained in:
zhl 2021-12-22 12:16:00 +08:00
parent ba215923ec
commit 7ee2576267
3 changed files with 11 additions and 7 deletions

View File

@ -3,6 +3,7 @@ import { role, router } from '../decorators/router'
import { GameCache } from '../models/GameCache' import { GameCache } from '../models/GameCache'
import { getJumpGameInfo, getJumpGamePrice } from '../services/jump.svr' import { getJumpGameInfo, getJumpGamePrice } from '../services/jump.svr'
import { GamePriceCache } from '../models/GamePriceCache' import { GamePriceCache } from '../models/GamePriceCache'
const timeOut = 8 * 3600 * 1000
class GameProxyController extends BaseController { class GameProxyController extends BaseController {
/** /**
@ -14,7 +15,8 @@ class GameProxyController extends BaseController {
let { accountId, oldGameId } = req.params let { accountId, oldGameId } = req.params
oldGameId += '' oldGameId += ''
let game = await GameCache.insertOrUpdate({ oldGameId }, {}) let game = await GameCache.insertOrUpdate({ oldGameId }, {})
if (game.inited) { let now = Date.now()
if (now - game.lastupdate > timeOut) {
try { try {
let res = await getJumpGameInfo(oldGameId) let res = await getJumpGameInfo(oldGameId)
if (res.success) { if (res.success) {
@ -23,7 +25,7 @@ class GameProxyController extends BaseController {
game.dlcList = data.dlcList game.dlcList = data.dlcList
game.jumpGameExt = data.jumpGameExt game.jumpGameExt = data.jumpGameExt
game.otherPlatVersion = data.otherPlatVersion game.otherPlatVersion = data.otherPlatVersion
game.inited = false game.lastupdate = Date.now()
await game.save() await game.save()
} }
} catch (err) { } catch (err) {
@ -43,7 +45,8 @@ class GameProxyController extends BaseController {
nums = nums | 0 || 0 nums = nums | 0 || 0
oldGameId += '' oldGameId += ''
let game = await GamePriceCache.insertOrUpdate({ oldGameId }, {}) let game = await GamePriceCache.insertOrUpdate({ oldGameId }, {})
if (game.inited) { let now = Date.now()
if (now - game.lastupdate > timeOut) {
try { try {
let res = await getJumpGamePrice(oldGameId) let res = await getJumpGamePrice(oldGameId)
if (res.success) { if (res.success) {

View File

@ -25,8 +25,9 @@ class GameCacheClass extends BaseModule {
@prop({ type: mongoose.Schema.Types.Mixed }) @prop({ type: mongoose.Schema.Types.Mixed })
public otherPlatVersion: any public otherPlatVersion: any
@prop({ default: true })
public inited: boolean @prop({ default: 0 })
public lastupdate: number
public toJson(): any { public toJson(): any {
let result: any = {} let result: any = {}

View File

@ -17,8 +17,8 @@ class GamePriceCacheClass extends BaseModule {
countries: any countries: any
@prop({ type: mongoose.Schema.Types.Mixed }) @prop({ type: mongoose.Schema.Types.Mixed })
public prices: any public prices: any
@prop({ default: true }) @prop({ default: 0 })
public inited: boolean public lastupdate: number
public toJson(): any { public toJson(): any {
let result: any = {} let result: any = {}