Fixed new profiles not being assigned avatars appropriately.
This commit is contained in:
parent
5edf781da7
commit
df820e6e71
|
@ -528,15 +528,23 @@ async function curateProfile(profile, actor) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function insertProfiles(newProfiles) {
|
||||||
|
if (newProfiles.length > 0) {
|
||||||
|
const entries = await bulkInsert('actors_profiles', newProfiles);
|
||||||
|
|
||||||
|
logger.info(`Saved ${newProfiles.length} actor profiles`);
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
async function upsertProfiles(profiles) {
|
async function upsertProfiles(profiles) {
|
||||||
const newProfileEntries = profiles.filter((profile) => !profile.update).map((profile) => curateProfileEntry(profile)).filter(Boolean);
|
const newProfileEntries = profiles.filter((profile) => !profile.update).map((profile) => curateProfileEntry(profile)).filter(Boolean);
|
||||||
const updatingProfileEntries = profiles.filter((profile) => profile.update).map((profile) => curateProfileEntry(profile)).filter(Boolean);
|
const updatingProfileEntries = profiles.filter((profile) => profile.update).map((profile) => curateProfileEntry(profile)).filter(Boolean);
|
||||||
|
|
||||||
if (newProfileEntries.length > 0) {
|
const newProfiles = await insertProfiles(newProfileEntries);
|
||||||
await bulkInsert('actors_profiles', newProfileEntries);
|
|
||||||
|
|
||||||
logger.info(`Saved ${newProfileEntries.length} actor profiles`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argv.force && updatingProfileEntries.length > 0) {
|
if (argv.force && updatingProfileEntries.length > 0) {
|
||||||
const transaction = await knex.transaction();
|
const transaction = await knex.transaction();
|
||||||
|
@ -554,12 +562,24 @@ async function upsertProfiles(profiles) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profiles.length > 0) {
|
if (profiles.length > 0) {
|
||||||
|
const newProfileIdMap = newProfiles.reduce((acc, profile) => {
|
||||||
|
if (!acc[profile.actor_id]) {
|
||||||
|
acc[profile.actor_id] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
acc[profile.actor_id][profile.entity_id] = profile.id;
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const avatars = profiles.filter((profile) => !!profile.avatarMediaId).map((profile) => ({
|
||||||
|
actor_id: profile.actorId,
|
||||||
|
profile_id: profile.profileId || newProfileIdMap[profile.actorId]?.[profile.entity?.id],
|
||||||
|
media_id: profile.avatarMediaId,
|
||||||
|
}));
|
||||||
|
|
||||||
await knex('actors_avatars')
|
await knex('actors_avatars')
|
||||||
.insert(profiles.filter((profile) => !!profile.avatarMediaId).map((profile) => ({
|
.insert(avatars)
|
||||||
actor_id: profile.actorId,
|
|
||||||
profile_id: profile.profileId,
|
|
||||||
media_id: profile.avatarMediaId,
|
|
||||||
})))
|
|
||||||
.onConflict()
|
.onConflict()
|
||||||
.ignore();
|
.ignore();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue