Skip to content

#143 Added remove BR feature#176

Open
PrinceK-Git wants to merge 1 commit into
devfrom
add-remove-br-feature
Open

#143 Added remove BR feature#176
PrinceK-Git wants to merge 1 commit into
devfrom
add-remove-br-feature

Conversation

@PrinceK-Git

Copy link
Copy Markdown

No description provided.

@RsbhThakur RsbhThakur linked an issue Jul 2, 2026 that may be closed by this pull request
@RsbhThakur RsbhThakur self-requested a review July 3, 2026 05:16
const br = await BR.findOneAndDelete({ email: normalizedEmail });
if (!br) return res.status(404).json({ error: "BR not found" });

const user = await findUserByEmailInsensitive(normalizedEmail);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, we are making two database trips here: one to read the user (findUserByEmailInsensitive) and one to write the change (user.save()). Since we only need to flip a boolean, we can optimize this into a single atomic database query using updateOne which reduces the network latency:

await User.updateOne(
    { email: normalizedEmail },
    { $set: { isBR: false } },
    { collation: { locale: "en", strength: 2 } }
);

@RsbhThakur RsbhThakur left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice Work!
While testing in local, I noticed that while adding a BR causes the frontend spinner to freeze for about 30-40 seconds. This happens because await fetchCoursesForBr(user.rollNumber) at line 29 and 68 in server/modules/br/br.controller.js scrapes the academic portal synchronously and blocks the HTTP response from returning.
Could you make this non-blocking by removing the await and adding a catch block? It will make the UI feel instant again while the courses fetch quietly in the background.
Suggested change in both createBR and updateBRs:

fetchCoursesForBr(user.rollNumber).catch((err) => logger.error(err));

Tested in local by deleting the br - the br access was removed from the client, everything looks good to me, the pr is clean and self contained and working. just fix the two improvements as mentioned in this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BR Handling (1)

2 participants