Hello
I have a webapp where a _User
can add a Tag
to a bunch of Profile
. For example, as a User, I have a list of 3577 profiles and I want to bulk update them with the tag “Friend”.
I achieved this with the following snippet but it tooks a lot of time to be executed. I would expect to be done in <5 seconds, is there a way?
Here is my collection attributes, very simple:
Profile :
firstName: string
lastName: string
Tag :
title: string,
color: string,
tagged: relation<Profile>
And code to mass ADD the tag with id Kv6YISgDqq
to a list of profiles:
// 1. find profile ids
const pipeline = getConnectionsProfileIdsPipeline(me, filters);
const documents = await new Parse.Query(ParseConnection).aggregate<Document[]>(pipeline); // <- this one executes very fast ~0.2 sec
const ids = documents.map((d) => d.id);
// 2. find the tag, add profiles to the tagged relation and save the tag
const parseTag = ParseTag.createWithoutData("Kv6YISgDqq") as ParseTag;
await parseTag.fetch({ sessionToken });
const tagged = parseTag.get("tagged");
ids.forEach((id) => {
tagged.add(_createParseProfileWithoutData(id));
});
await parseTag.save(null, { sessionToken }); // <- TAG added [ Friend ] to 3577 profiles. Took: 104.708 secs
I am doing the right thing? How can I boost this request? My database is hosted on mongodb atlas and Parse Server on heroku. Also I ensured the _Join:tagged:Tag
table is indexed as shown below.
Thank you very much for your help.