WIP: Improve User model performances (#10832)

* wip: define items as mixed objects

* add default owned gear

* mark modified

* more mark modified

* more mark modified

* more mark modified

* more mark modified

* fix common tests

* fix common tests

* update mongoose

* add itemsUtils

* use new util function in hall controller

* add tests for items utils

* update website/server to mark all items as modified

* start updating common code

* update login incentives

* update unlock

* remove changes to package-lock.json

* remove changes to package.json
This commit is contained in:
Matteo Pagliazzi
2019-04-01 19:24:18 +02:00
committed by GitHub
parent 95e541ae75
commit 0b8ce63c76
38 changed files with 304 additions and 42 deletions

View File

@@ -1,6 +1,5 @@
import mongoose from 'mongoose';
import shared from '../../../common';
import _ from 'lodash';
import validator from 'validator';
import { schema as TagSchema } from '../tag';
import { schema as PushDeviceSchema } from '../pushDevice';
@@ -11,6 +10,9 @@ import {
import {
schema as SubscriptionPlanSchema,
} from '../subscriptionPlan';
import {
getDefaultOwnedGear,
} from '../../libs/items/utils';
const Schema = mongoose.Schema;
@@ -251,12 +253,12 @@ let schema = new Schema({
items: {
gear: {
owned: _.transform(shared.content.gear.flat, (m, v) => {
m[v.key] = {$type: Boolean};
if (v.key.match(/(armor|head|shield)_warrior_0/) || v.gearSet === 'glasses' || v.gearSet === 'headband') {
m[v.key].default = true;
}
}),
owned: {
$type: Schema.Types.Mixed,
default: () => {
return getDefaultOwnedGear();
},
},
equipped: {
weapon: String,
@@ -310,55 +312,52 @@ let schema = new Schema({
// 'PandaCub-Red': 10, // Number represents "Growth Points"
// etc...
// }
pets: _.defaults(
// First transform to a 1D eggs/potions mapping
_.transform(shared.content.pets, (m, v, k) => m[k] = Number),
// Then add additional pets (quest, backer, contributor, premium)
_.transform(shared.content.questPets, (m, v, k) => m[k] = Number),
_.transform(shared.content.specialPets, (m, v, k) => m[k] = Number),
_.transform(shared.content.premiumPets, (m, v, k) => m[k] = Number)
),
pets: {$type: Schema.Types.Mixed, default: () => {
return {};
}},
currentPet: String, // Cactus-Desert
// eggs: {
// 'PandaCub': 0, // 0 indicates "doesn't own"
// 'Wolf': 5 // Number indicates "stacking"
// }
eggs: _.transform(shared.content.eggs, (m, v, k) => m[k] = Number),
eggs: {$type: Schema.Types.Mixed, default: () => {
return {};
}},
// hatchingPotions: {
// 'Desert': 0, // 0 indicates "doesn't own"
// 'CottonCandyBlue': 5 // Number indicates "stacking"
// }
hatchingPotions: _.transform(shared.content.hatchingPotions, (m, v, k) => m[k] = Number),
hatchingPotions: {$type: Schema.Types.Mixed, default: () => {
return {};
}},
// Food: {
// 'Watermelon': 0, // 0 indicates "doesn't own"
// 'RottenMeat': 5 // Number indicates "stacking"
// }
food: _.transform(shared.content.food, (m, v, k) => m[k] = Number),
food: {$type: Schema.Types.Mixed, default: () => {
return {};
}},
// mounts: {
// 'Wolf-Desert': true,
// 'PandaCub-Red': false,
// etc...
// }
mounts: _.defaults(
// First transform to a 1D eggs/potions mapping
_.transform(shared.content.pets, (m, v, k) => m[k] = Boolean),
// Then add quest and premium pets
_.transform(shared.content.questPets, (m, v, k) => m[k] = Boolean),
_.transform(shared.content.premiumPets, (m, v, k) => m[k] = Boolean),
// Then add additional mounts (backer, contributor)
_.transform(shared.content.specialMounts, (m, v, k) => m[k] = Boolean)
),
mounts: {$type: Schema.Types.Mixed, default: () => {
return {};
}},
currentMount: String,
// Quests: {
// 'boss_0': 0, // 0 indicates "doesn't own"
// 'collection_honey': 5 // Number indicates "stacking"
// }
quests: _.transform(shared.content.quests, (m, v, k) => m[k] = Number),
quests: {$type: Schema.Types.Mixed, default: () => {
return {};
}},
lastDrop: {
date: {$type: Date, default: Date.now},