WIP(shops): better Fennec and bg loading, add migration

This commit is contained in:
Sabe Jones
2024-05-28 17:57:13 -05:00
parent 19521b1894
commit 2062c68877
4 changed files with 167 additions and 28 deletions

View File

@@ -0,0 +1,143 @@
/* eslint-disable no-console */
const MIGRATION_NAME = '20240621_veteran_pet_ladder';
import { model as User } from '../../../website/server/models/user';
const progressCount = 1000;
let count = 0;
async function updateUser (user) {
count++;
const set = {};
let push = { notifications: { $each: [] }};
set.migration = MIGRATION_NAME;
if (user.items.pets['Dragon-Veteran']) {
set['items.pets.Cactus-Veteran'] = 5;
push.notifications.$each.push({
type: 'ITEM_RECEIVED',
data: {
icon: 'icon_pet_veteran_cactus',
title: 'Youve received a Veteran Pet!',
text: 'To commemorate being here for a new era of Habitica, weve awarded you a Veteran Cactus.',
destination: '/inventory/stable',
},
seen: false,
});
} else if (user.items.pets['Fox-Veteran']) {
set['items.pets.Dragon-Veteran'] = 5;
push.notifications.$each.push({
type: 'ITEM_RECEIVED',
data: {
icon: 'icon_pet_veteran_dragon',
title: 'Youve received a Veteran Pet!',
text: 'To commemorate being here for a new era of Habitica, weve awarded you a Veteran Dragon.',
destination: '/inventory/stable',
},
seen: false,
});
} else if (user.items.pets['Bear-Veteran']) {
set['items.pets.Fox-Veteran'] = 5;
push.notifications.$each.push({
type: 'ITEM_RECEIVED',
data: {
icon: 'icon_pet_veteran_fox',
title: 'Youve received a Veteran Pet!',
text: 'To commemorate being here for a new era of Habitica, weve awarded you a Veteran Fox.',
destination: '/inventory/stable',
},
seen: false,
});
} else if (user.items.pets['Lion-Veteran']) {
set['items.pets.Bear-Veteran'] = 5;
push.notifications.$each.push({
type: 'ITEM_RECEIVED',
data: {
icon: 'icon_pet_veteran_bear',
title: 'Youve received a Veteran Pet!',
text: 'To commemorate being here for a new era of Habitica, weve awarded you a Veteran Bear.',
destination: '/inventory/stable',
},
seen: false,
});
} else if (user.items.pets['Tiger-Veteran']) {
set['items.pets.Lion-Veteran'] = 5;
push.notifications.$each.push({
type: 'ITEM_RECEIVED',
data: {
icon: 'icon_pet_veteran_lion',
title: 'Youve received a Veteran Pet!',
text: 'To commemorate being here for a new era of Habitica, weve awarded you a Veteran Lion.',
destination: '/inventory/stable',
},
seen: false,
});
} else if (user.items.pets['Wolf-Veteran']) {
set['items.pets.Tiger-Veteran'] = 5;
push.notifications.$each.push({
type: 'ITEM_RECEIVED',
data: {
icon: 'icon_pet_veteran_tiger',
title: 'Youve received a Veteran Pet!',
text: 'To commemorate being here for a new era of Habitica, weve awarded you a Veteran Tiger.',
destination: '/inventory/stable',
},
seen: false,
});
} else {
set['items.pets.Wolf-Veteran'] = 5;
push.notifications.$each.push({
type: 'ITEM_RECEIVED',
data: {
icon: 'icon_pet_veteran_wolf',
title: 'Youve received a Veteran Pet!',
text: 'To commemorate being here for a new era of Habitica, weve awarded you a Veteran Wolf.',
destination: '/inventory/stable',
},
seen: false,
});
}
if (count % progressCount === 0) console.warn(`${count} ${user._id}`);
return await User.updateOne(
{ _id: user._id },
{ $set: set, $push: push, $inc: { 'balance': 6 } },
).exec();
}
export default async function processUsers () {
let query = {
migration: {$ne: MIGRATION_NAME},
'auth.timestamps.loggedin': { $gt: new Date('2024-05-21') },
};
const fields = {
_id: 1,
items: 1,
migration: 1,
contributor: 1,
};
while (true) { // eslint-disable-line no-constant-condition
const users = await User // eslint-disable-line no-await-in-loop
.find(query)
.limit(250)
.sort({_id: 1})
.select(fields)
.lean()
.exec();
if (users.length === 0) {
console.warn('All appropriate users found and modified.');
console.warn(`\n${count} users processed\n`);
break;
} else {
query._id = {
$gt: users[users.length - 1],
};
}
await Promise.all(users.map(updateUser)); // eslint-disable-line no-await-in-loop
}
};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

@@ -987,7 +987,6 @@
<script> <script>
import axios from 'axios'; import axios from 'axios';
import forEach from 'lodash/forEach'; import forEach from 'lodash/forEach';
import orderBy from 'lodash/orderBy';
import content from '@/../../common/script/content/index'; import content from '@/../../common/script/content/index';
import { mapState } from '@/libs/store'; import { mapState } from '@/libs/store';
import avatar from './avatar'; import avatar from './avatar';
@@ -1090,39 +1089,33 @@ export default {
}, },
}, },
mounted () { mounted () {
forEach(this.allBackgrounds, bg => { this.updateBackgrounds();
if (bg.set === 'incentiveBackgrounds') {
this.standardBackgroundMax += 1;
}
if (this.user.purchased.background[bg.key]) {
if (bg.set === 'incentiveBackgrounds') {
this.standardBackgrounds.push(bg);
} else if (bg.set === 'timeTravelBackgrounds') {
this.timeTravelBackgrounds.push(bg);
} else {
this.monthlyBackgrounds.push(bg);
}
}
});
this.monthlyBackgrounds = orderBy(this.monthlyBackgrounds, bg => bg.key, 'desc');
this.standardBackgrounds.splice(0, 0, { key: '', notes: () => this.$t('noBackground') });
if (this.editing) this.modalPage = 2; if (this.editing) this.modalPage = 2;
this.$root.$on('buyModal::boughtItem', item => {
if (item.path.includes('background')) {
const newBackground = this.allBackgrounds[item.path.split('.')[2]];
if (newBackground.set === 'timeTravelBackgrounds') {
this.timeTravelBackgrounds.push(newBackground);
} else {
this.monthlyBackgrounds.push(newBackground);
this.monthlyBackgrounds = orderBy(this.monthlyBackgrounds, bg => bg.key, 'desc');
}
}
});
}, },
methods: { methods: {
close () { close () {
this.$root.$emit('bv::hide::modal', 'avatar-modal'); this.$root.$emit('bv::hide::modal', 'avatar-modal');
}, },
updateBackgrounds () {
this.monthlyBackgrounds = [];
this.standardBackgrounds = [
{ key: '', notes: () => this.$t('noBackground') },
];
forEach(this.allBackgrounds, bg => {
if (bg.set === 'incentiveBackgrounds') {
this.standardBackgroundMax += 1;
}
if (this.user.purchased.background[bg.key]) {
if (bg.set === 'incentiveBackgrounds') {
this.standardBackgrounds.push(bg);
} else if (bg.set === 'timeTravelBackgrounds') {
this.timeTravelBackgrounds.push(bg);
} else {
this.monthlyBackgrounds.push(bg);
}
}
});
},
prev () { prev () {
this.modalPage -= 1; this.modalPage -= 1;
}, },
@@ -1130,6 +1123,9 @@ export default {
this.modalPage += 1; this.modalPage += 1;
}, },
changeTopPage (page, subpage) { changeTopPage (page, subpage) {
if (page === 'backgrounds') {
this.updateBackgrounds();
}
this.activeTopPage = page; this.activeTopPage = page;
if (subpage) this.activeSubPage = subpage; if (subpage) this.activeSubPage = subpage;
}, },