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 genresinfo = await getGenres([...cachedGenres]);
const genres = []; const genres = [];

View File

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