Improve the performance of the ArtistBrowser's data collation (closes #26)
This commit is contained in:
parent
6e4aba02dc
commit
92a5282e36
1 changed files with 20 additions and 14 deletions
|
|
@ -152,6 +152,24 @@ export class ArtistBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
const allArtists = Object.entries(deepClone(this.#artistDB.data));
|
||||
const allImages = Object.values(this.#imagesDB.data);
|
||||
|
||||
/*
|
||||
This collates all of the image data into the required summary data for the
|
||||
display of the artists. Because this does the collation all in one iteration
|
||||
it is a more performant way of collecting all of the information once the
|
||||
databases get larger
|
||||
*/
|
||||
const summary = {};
|
||||
for (const image of allImages) {
|
||||
for (const artistID of image.artists) {
|
||||
summary[artistID] ??= { count: 0, tags: {} };
|
||||
summary[artistID].count++;
|
||||
for (const tag of image.tags) {
|
||||
summary[artistID].tags[tag] ??= { name: tag, count: 0 };
|
||||
summary[artistID].tags[tag].count++;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
const artists = [];
|
||||
for (const [id, artist] of allArtists) {
|
||||
// Check if it matches the required filters
|
||||
|
|
@ -162,20 +180,8 @@ export class ArtistBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
|
|||
// Populate ephemeral data for rendering
|
||||
artist.id = id;
|
||||
|
||||
let imageCount = 0;
|
||||
let tags = {};
|
||||
|
||||
for (const image of allImages) {
|
||||
if (!image.artists.includes(id)) continue;
|
||||
imageCount++;
|
||||
for (const tag of image.tags) {
|
||||
tags[tag] ??= { name: tag, count: 0 };
|
||||
tags[tag].count++;
|
||||
};
|
||||
};
|
||||
|
||||
artist.imageCount = imageCount;
|
||||
artist.commonTags = Object.values(tags)
|
||||
artist.imageCount = summary[id].count;
|
||||
artist.commonTags = Object.values(summary[id].tags)
|
||||
.sort((a, b) => b.count - a.count)
|
||||
.slice(0, 5);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue