Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(indexer): handle db update when children is null instead of array #82

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/Database/Inscriptions/Methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ async function insertMany(inscriptions: Inscription[], chunkSize = getChunkSize(
for (const inscription of chunk) {
if (inscription.parents) {
for (const parent of inscription.parents) {
promises.push(collection.updateOne({ id: parent }, { $addToSet: { children: inscription.id } }));
promises.push(
collection.updateOne({ id: parent }, [
{
$set: {
children: {
$ifNull: [{ $concatArrays: ["$children", [inscription.id]] }, [inscription.id]],
},
},
},
]),
);
}
}
}
Expand All @@ -65,7 +75,15 @@ async function insertOne(inscription: Inscription) {
// Check for parents in Inscriptions and update children
if (inscription.parents) {
for (const parent of inscription.parents) {
await collection.updateOne({ id: parent }, { $addToSet: { children: inscription.id } });
await collection.updateOne({ id: parent }, [
{
$set: {
children: {
$ifNull: [{ $concatArrays: ["$children", [inscription.id]] }, [inscription.id]],
},
},
},
]);
}
}
return collection.updateOne({ id: inscription.id }, { $set: inscription }, { upsert: true });
Expand Down