diff --git a/package.json b/package.json index c5cec3b..a844342 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "repairdata2": "ts-node -r tsconfig-paths/register src/repairdata2.ts", "repairredis": "ts-node -r tsconfig-paths/register src/repairredis.ts", "checkredis": "ts-node -r tsconfig-paths/register src/checkredis.ts", + "additem": "ts-node -r tsconfig-paths/register src/addboxdata.ts", "test:watch": "jest --watch", "test": "jest" }, diff --git a/src/addboxdata.ts b/src/addboxdata.ts new file mode 100644 index 0000000..f65bf97 --- /dev/null +++ b/src/addboxdata.ts @@ -0,0 +1,43 @@ +import mongoose from 'mongoose' +import * as dotenv from 'dotenv' + +const envFile = process.env.NODE_ENV && process.env.NODE_ENV === 'production' ? `.env.production` : '.env.development' +dotenv.config({ path: envFile }) +console.log(process.env.DB_MAIN) +import { ActivityChest } from 'models/ActivityChest' +import { ScoreRecord } from 'models/ScoreRecord' +import { DeleteRecord } from 'models/DeleteRecord' +import { rankKey, updateRank, updateRankInvite } from 'services/rank.svr' +import { ZRedisClient } from 'zutils' +import { RANK_SCORE_SCALE } from 'common/Constants' +import { uuid } from 'zutils/utils/security.util' +const db = mongoose.connection + +const totalKey = 'uaw_activity:score' +const keyInvite = `uaw_activity:invite` + +const addItem = async (key, item) => { + return new Promise((resolve, reject) => { + new ZRedisClient().pub.sadd(key, item, () => { + resolve(true) + }) + }) +} +;(async () => { + try { + let opts = { url: process.env.REDIS } + new ZRedisClient(opts) + for (let i = 0; i < 10; i++) { + let id = uuid() + await addItem('chest_bonus_1', id) + } + for (let i = 0; i < 100; i++) { + let id = uuid() + await addItem('chest_bonus_2', id) + } + } catch (e) { + console.log(e) + } + console.log('end') + process.exit(0) +})() diff --git a/src/controllers/chest.controller.ts b/src/controllers/chest.controller.ts index 9a016e0..e48691b 100644 --- a/src/controllers/chest.controller.ts +++ b/src/controllers/chest.controller.ts @@ -320,9 +320,11 @@ class BoxController extends BaseController { if (!isObjectIdString(chestId)) { throw new ZError(11, 'must provide valid chestId') } - const openRecord = await ChestRecord.findOne({ from: user.address.toLowerCase(), chestId }) - if (!openRecord) { - throw new ZError(12, 'onchain open record not found') + if (process.env.NODE_ENV === 'production') { + const openRecord = await ChestRecord.findOne({ from: user.address.toLowerCase(), chestId }) + if (!openRecord) { + throw new ZError(12, 'onchain open record not found') + } } const chest = await ActivityChest.findById(chestId) if (!chest) { diff --git a/src/controllers/game.controller.ts b/src/controllers/game.controller.ts index c5bb100..a4ac052 100644 --- a/src/controllers/game.controller.ts +++ b/src/controllers/game.controller.ts @@ -352,13 +352,15 @@ class GameController extends BaseController { if (!isObjectId(id)) { throw new ZError(12, 'invalid id') } - const chainRecord = await GeneralScription.findOne({ - from: user.address.toLowerCase(), - op: 'explore', - data: id, - }) - if (!chainRecord) { - throw new ZError(13, 'waiting for chain confirm') + if (process.env.NODE_ENV === 'production') { + const chainRecord = await GeneralScription.findOne({ + from: user.address.toLowerCase(), + op: 'explore', + data: id, + }) + if (!chainRecord) { + throw new ZError(13, 'waiting for chain confirm') + } } const exploreRecord = await ExploreRecord.findById(id) if (!exploreRecord) {