Skip to content

Commit

Permalink
back to a lightly async process for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerFisher committed Nov 25, 2024
1 parent 0f992a3 commit dbcc068
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions app/routes/api.update-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,25 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
users = users.slice(start, end);

const redis = connection();
const chunkSize = 50;
const chunkSize = 10;
for (let i = 0; i < users.length; i += chunkSize) {
const userChunk = users.slice(i, i + chunkSize);
const processedResults: ProcessedResult[] = [];

for (const user of userChunk) {
try {
const results = await fetchLinks(user.id);
processedResults.push(...results);
} catch (error) {
console.error(
"error fetching links for",
user.mastodonAccounts[0].mastodonInstance.instance,
error,
);
}
}
await Promise.all(
userChunk.map(async (user) => {
try {
const results = await fetchLinks(user.id);
processedResults.push(...results);
} catch (error) {
console.error(
"error fetching links for",
user.mastodonAccounts[0].mastodonInstance.instance,
error,
);
}
}),
);

await insertNewLinks(processedResults);
}
Expand Down

0 comments on commit dbcc068

Please sign in to comment.