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

@@ -75,6 +75,8 @@ module.exports = function randomDrop (user, options, req = {}, analytics) {
user.items.food[drop.key] = user.items.food[drop.key] || 0;
user.items.food[drop.key] += 1;
if (user.markModified) user.markModified('items.food');
drop.type = 'Food';
drop.dialog = i18n.t('messageDropFood', {
dropText: drop.textA(req.language),
@@ -82,8 +84,11 @@ module.exports = function randomDrop (user, options, req = {}, analytics) {
}, req.language);
} else if (rarity > 0.3) { // eggs 30% chance
drop = cloneDropItem(randomVal(content.dropEggs));
user.items.eggs[drop.key] = user.items.eggs[drop.key] || 0;
user.items.eggs[drop.key]++;
if (user.markModified) user.markModified('items.eggs');
drop.type = 'Egg';
drop.dialog = i18n.t('messageDropEgg', {
dropText: drop.text(req.language),
@@ -102,8 +107,11 @@ module.exports = function randomDrop (user, options, req = {}, analytics) {
drop = cloneDropItem(randomVal(pickBy(content.hatchingPotions, (v, k) => {
return acceptableDrops.indexOf(k) >= 0;
})));
user.items.hatchingPotions[drop.key] = user.items.hatchingPotions[drop.key] || 0;
user.items.hatchingPotions[drop.key]++;
if (user.markModified) user.markModified('items.hatchingPotions');
drop.type = 'HatchingPotion';
drop.dialog = i18n.t('messageDropPotion', {
dropText: drop.text(req.language),

View File

@@ -12,7 +12,7 @@ module.exports = function resetGear (user) {
gear[type].shield = 'shield_base_0';
});
// Gear.owned is a Mongo object so the _.each function iterates over hidden properties.
// Gear.owned is (was) a Mongo object so the _.each function iterates over hidden properties.
// The content.gear.flat[k] check should prevent this causing an error
each(gear.owned, function resetOwnedGear (v, k) {
if (gear.owned[k] && content.gear.flat[k] && content.gear.flat[k].value) {
@@ -21,5 +21,7 @@ module.exports = function resetGear (user) {
});
gear.owned.weapon_warrior_0 = true; // eslint-disable-line camelcase
if (user.markModified) user.markModified('items.gear.owned');
user.preferences.costume = false;
};

View File

@@ -4,7 +4,7 @@ import reduce from 'lodash/reduce';
import includes from 'lodash/includes';
module.exports = function ultimateGear (user) {
let owned = typeof window !== 'undefined' ? user.items.gear.owned : user.items.gear.owned.toObject();
let owned = user.items.gear.owned.toObject ? user.items.gear.owned.toObject() : user.items.gear.owned;
content.classes.forEach((klass) => {
if (user.achievements.ultimateGearSets[klass] !== true) {

View File

@@ -75,6 +75,8 @@ module.exports = function updateStats (user, stats, req = {}, analytics) {
} else {
user.items.eggs.Wolf = 1;
}
if (user.markModified) user.markModified('items.eggs');
}
each({
vice1: 30,
@@ -84,10 +86,12 @@ module.exports = function updateStats (user, stats, req = {}, analytics) {
}, (lvl, k) => {
if (user.stats.lvl >= lvl && !user.flags.levelDrops[k]) {
user.flags.levelDrops[k] = true;
if (!user.items.quests[k])
user.items.quests[k] = 0;
user.items.quests[k]++;
if (user.markModified) user.markModified('flags.levelDrops');
if (!user.items.quests[k]) user.items.quests[k] = 0;
user.items.quests[k]++;
if (user.markModified) user.markModified('items.quests');
if (analytics) {
analytics.track('acquire item', {
uuid: user._id,