Add initial batching to wrapped

This commit is contained in:
baz 2025-05-13 23:52:39 +01:00
parent 7cb3ca3e58
commit e01dfd8291
2 changed files with 17 additions and 16 deletions

View File

@ -72,7 +72,6 @@ module.exports = {
}
}
const genresinfo = await getGenres([...cachedGenres]);
const genres = [];

View File

@ -103,13 +103,14 @@ async function GetBeatenGamesForYear(userDatabaseEntry, year) {
}
async function GetIGDBEntries(array) {
beatGameIGDBEntries = [];
const gameIds = [];
for (let i = 0; i < array.length; i++) {
const game = await checkGameStorageId(array[i].gameId);
const json = await getGameJson(String.prototype.concat('where id = ', game.igdb_id, '; fields *;'));
beatGameIGDBEntries.push(json[0]);
gameIds.push(game.igdb_id);
}
beatGameIGDBEntries = await getGameJson(String.prototype.concat(`where id = (${gameIds}); fields *; limit ${gameIds.length};`));
}
async function GetDevelopers() {
@ -257,24 +258,25 @@ async function GetAverageGameAge() {
}
async function GetFavouriteGenres() {
const genres = [];
const counts = [];
const cachedGenres = new Map();
const cachedGenres = new Set();
for (let i = 0; i < beatGameIGDBEntries.length; i++) {
if (beatGameIGDBEntries[i].genres) {
for (let j = 0; j < beatGameIGDBEntries[i].genres.length; j++) {
cachedGenres.add(beatGameIGDBEntries[i].genres[j]);
}
}
}
if (cachedGenres.has(beatGameIGDBEntries[i].genres[j]))
{
genres.push(cachedGenres.get(beatGameIGDBEntries[i].genres[j]));
}
else
{
const genre = await getGenres(beatGameIGDBEntries[i].genres[j]);
cachedGenres.set(beatGameIGDBEntries[i].genres[j], genre);
genres.push(genre);
}
const genresinfo = await getGenres([...cachedGenres]);
const genres = [];
for (let i = 0; i < beatGameIGDBEntries.length; i++) {
if (beatGameIGDBEntries[i].genres) {
for (let j = 0; j < beatGameIGDBEntries[i].genres.length; j++) {
genres.push(genresinfo.find(item => item.id === beatGameIGDBEntries[i].genres[j]).name);
}
}
}