-
Notifications
You must be signed in to change notification settings - Fork 263
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
feat: Integrate userData into Progresses API to reduce redundant calls #2311
base: develop
Are you sure you want to change the base?
feat: Integrate userData into Progresses API to reduce redundant calls #2311
Conversation
|
||
if (dev) { | ||
try { | ||
const uniqueUserIds = [...new Set(progressDocs.map((doc) => doc.userId))]; | ||
const batchSize = 500; | ||
|
||
const batches = Array.from({ length: Math.ceil(uniqueUserIds.length / batchSize) }, (_, index) => | ||
uniqueUserIds.slice(index * batchSize, index * batchSize + batchSize) | ||
); | ||
|
||
const batchPromises = batches.map((batch) => Promise.all(batch.map((userId) => fetchUser({ userId })))); | ||
|
||
const usersDataBatches = await Promise.all(batchPromises); | ||
|
||
const usersData = usersDataBatches.flat(); | ||
|
||
const userLookupMap = usersData.reduce((lookup, { user }) => { | ||
if (user) lookup[user.id] = user; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write tests for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @Achintya-Chatterjee I just need some clarification regarding the tests. I can add a test to check that userData returns null if the operation fails, but I'm also wondering how to test for scenarios with a large number of unique users. With our current test setup, I would need to add 1000+ users to Firestore to test it.
If you want me to proceed with that approach, please let me know!
Please fix the title as commit message is not the title |
|
||
if (dev) { | ||
try { | ||
const uniqueUserIds = [...new Set(progressDocs.map((doc) => doc.userId))]; | ||
const batchSize = 500; | ||
|
||
const batches = Array.from({ length: Math.ceil(uniqueUserIds.length / batchSize) }, (_, index) => | ||
uniqueUserIds.slice(index * batchSize, index * batchSize + batchSize) | ||
); | ||
|
||
const batchPromises = batches.map((batch) => Promise.all(batch.map((userId) => fetchUser({ userId })))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refactor this and why we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Achintya asked me to use the batches approach as Promise.all could cause performance issues for large datasets. You can check the prevoius resolved messages
Date: 21 Dec 2024
Developer Name: Anuj Chhikara
Issue Ticket Number
Description
This PR introduces a change to include the full
userData
(e.g., username, profile picture) alongside the progress data when fetching progress updates. Currently, the backend only returns theuserId
, requiring the frontend to make an additional API call to fetch user details. By includinguserData
directly with the progress object, we aim to reduce the number of API calls and improve frontend performance and simplicity.Documentation Updated?
Under Feature Flag
Database Changes
Breaking Changes
Development Tested?
Screenshots
Screenshot 1
Without dev flag
With dev flag
Test Coverage
Screenshot 1
Additional Notes