Skip to content

London | 26-SDC-July | Raihan Sharif | Sprint 2 | rebloom - #321

Open
RaihanSharif wants to merge 41 commits into
CodeYourFuture:mainfrom
RaihanSharif:feature/rebloom
Open

RaihanSharif wants to merge 41 commits into
CodeYourFuture:mainfrom
RaihanSharif:feature/rebloom

Conversation

@RaihanSharif

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Task code

CYF-1171

Changelist

Blooms have a rebloom button, and rebloom count.

Users can "rebloom" a bloom they haven't already rebloomed.

On reblooming:

the rebloom gets added to the user's timeline, and their profile timeline.
reblooms by followed users also gets added to the home timeline.
reblooms done by currently logged in user are green.
reblooms by other users are in purple.
all reblooms are non-rebloomable. You must go to the original to rebloom.

Fetches blooms on navigation to a page, as stale cache was an issue.

initial implementation of how reblooms will be recorded.

A rebloom refers to a bloom, and rebloomer.

Get rebloom count by number of rows for a given bloom id in reblooms table.
By combining the blooms and reblooms, the home_timeline, other_profile endpoints don't have to change much.
The before clause now uses WHERE because it's filtering the combined blooms/reblooms.

Use correct placeholder for username
add a helper function to get reblooms by a user from a given list of blooms.
@RaihanSharif RaihanSharif added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 22, 2026

@iscmiguelsamaniego iscmiguelsamaniego left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Solid, modular Rebloom feature! Just clean up the duplicate returns in Python, wrap your rebloom button states in try...finally, add .catch() error handling to routing fetches, and round out your .gitignore with Python/Node exclusions.

Comment thread backend/data/blooms.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great progress on the reblooms implementation! Here are two quick questions to help refine the code:

  1. Duplicate returns: In functions like home_timeline, user_blooms, and hashtag, did you notice consecutive return statements? How might that affect whether _mark_rebloomed_by_me gets executed?
  2. Query performance: By using subqueries to count reblooms for every row in the main queries, how do you think the database performance will scale as the dataset grows?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

On the first question, I'm not quite sure what you're hinting at. Looking at those three functions again, it doesn't look like there's are consecutive return statements.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The count subquery runs once per row, every time a new profile or home timeline is viewed. Since the number of reblooms is not not stored anywhere such as on in the bloom table, every time someone views a timeline, the bloom count query has to run again.

So for example, if a bloom has 50 reblooms, it has to get those 50 entries in the rebloom table and do a count.

If a thousand different profiles show that bloom then there has to be 1000 * 50 counts. The amount of work in each view is proportional to the number of reblooms.

I could instead store the rebloom count, and that makes looking up rebloom count a O(1) operation.

Comment thread backend/endpoints.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great, Here are a couple of quick questions to help refine it:

  1. Unreachable Code: In functions like home_timeline, user_blooms, and hashtag, did you notice that the second return statement is placed right after the first one? How might that affect whether _mark_rebloomed_by_me is ever executed?
  2. Variable Definitions: In self_profile(), are profile_user and profile_username defined before they are used in followers and blooms.get_blooms_for_user()?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

  1. Again, I don't see repeated return statements.

  2. Did you mean other_profile? self_profile does not use those variables. In other_profile, the variables are defined beforehand. profile_username is a route parameter. For profile_user, there is a check for None before proceeding with the rest of the code.

Comment thread backend/main.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great routing setup! Notice the data type used for the port parameter in app.run()—might an integer be preferred there? Also, are all the imported view functions (like self_profile and register) accounted for in your URL rules?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

All view functions have been imported. and registered.

The port number is as it was given in the preexisting application, and I didn't touch it as it was working fine. After review, it should be an integer, but flask automatically converts string to an integer anyway.

Comment thread db/schema.sql

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clean schema design with proper constraints and well-chosen indexes! How do you envision reblooms_bloom_id_idx and reblooms_user_ts_idx supporting your queries for timelines and rebloom counts?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

reblooms_bloom_id_idx supports the count subquery SELECT COUNT(*) FROM reblooms rc WHERE rc.bloom_id = b.id, which runs for every bloom displayed. Without it, each count would have to go through the reblooms table sequentially. The index keeps bloom_id values sorted, so Postgres descends the B-tree once to the first matching entry, and since all the entries with a given bloom_id are together, it can count them all without having to do more searches. This makes finding a bloom’s reblooms cheap, though the count still visits every matching entry, so cost grows with a bloom’s rebloom count.

reblooms_user_ts_idx on (user_id, rebloom_timestamp DESC) supports the rebloom part of the query in get_blooms_for_user, which fetches a user’s reblooms newest-first. Entries for one user are contiguous and already ordered by timestamp, so the index can return them in display order.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clean component logic for rendering reblooms!

Notice how bloomFrag is queried right at the start before it's defined or cloned from the template—how might we ensure the template is properly cloned into bloomFrag before accessing its elements?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sorry, I'm confused. Is the bloomFrag variable's value assigned before any queries to it? In line 21 the template is cloned and the value is assigned to bloomFragment.

Do you mean that at this stage the template may not be correctly cloned, for example, because the template with the given id does not exist, it would throw an error?

Comment thread front-end/lib/router.mjs

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great job structuring the routing logic to cleanly distinguish between real navigation and state re-renders!

Notice how apiService.getBloom includes a .catch() for error handling—might the other profile and hashtag fetch calls also benefit from error handling to prevent unhandled rejections if a network request fails?

Comment thread front-end/index.css

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clean styling! Just consider using a CSS variable for the green border and ensure display: flex is set on the footer.

Comment thread front-end/index.html

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clean and well-structured HTML template! Just remove the duplicate comments and ensure you use cloneNode(true) when instantiating it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done!

Comment thread front-end/index.mjs

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great event delegation! Just make sure to pass event into your state-change listener, wrap the rebloom action in a try...finally to reset the button state on error, and remove the redundant refreshRouteData() call on load.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've wrapped the rebloom action in a try, catch, finally block. I'm not sure what you mean by passing event into the state-state listener.

document.addEventListener("state-change", () => {
    handleRouteChange();
  });

It would do nothing.

Removed refreshRouteData().

Comment thread .gitignore

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good start! Have you considered adding ignores for your Python (venv, __pycache__, .env) and Node (node_modules, dist) environments?

@takanocap takanocap added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Nov 13, 2026
@takanocap
takanocap requested review from takanocap and removed request for takanocap November 13, 2026 13:20
@takanocap takanocap self-assigned this Nov 13, 2026
@takanocap takanocap removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 13, 2026

@takanocap takanocap left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well done for the good job done. The PR LGTM. However, there is always room for improvement. There were just a few little issues to fix

Comment thread front-end/lib/router.mjs
function refreshRouteData() {
const hash = window.location.hash.substring(1) || "/";

if (hash.startsWith("/bloom/")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

a few questions here

  • why is getBlooms() safe without a catch .getBlooms() not
  • if the backend returns 404 what will getProfile("nobody") do resolve or throw ?

Comment thread front-end/lib/router.mjs Outdated
// getBloom has no error handling of its own, and the dialog already showed
apiService.getBloom(hash.split("/")[2]).catch(() => {});
} else if (hash.startsWith("/profile/")) {
apiService.getProfile(hash.split("/")[2]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if this a fire and forget is clearer to use "void" on line 22 and other calls without .catch()?

Comment thread front-end/lib/router.mjs

const href = link.getAttribute("href");
// Only handle internal links (starting with / and not # anchors)
if (href && href.startsWith("/") && !href.startsWith("#")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

could optional chaining help here ?

Comment thread backend/endpoints.py Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is there a missing replacement field here or its meant to be a normal string?

Comment thread backend/endpoints.py

# Sort by timestamp (newest first)
# Sort by timestamp of rebloom or timestamp of creation (newest first)
sorted_blooms = list(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is this needed or redundant ?

@takanocap takanocap added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Nov 14, 2026
@RaihanSharif RaihanSharif added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 15, 2026
@takanocap takanocap removed their assignment Nov 15, 2026
@takanocap takanocap added Reviewed Volunteer to add when completing a review with trainee action still to take. Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants