Repository navigation
London | 26-SDC-July | Raihan Sharif | Sprint 2 | rebloom - #321
RaihanSharif wants to merge 41 commits into
Conversation
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.
…ly logged in user
7e599de to
2f5b39a
Compare
iscmiguelsamaniego
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Great progress on the reblooms implementation! Here are two quick questions to help refine the code:
- Duplicate returns: In functions like
home_timeline,user_blooms, andhashtag, did you notice consecutivereturnstatements? How might that affect whether_mark_rebloomed_by_megets executed? - 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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Great, Here are a couple of quick questions to help refine it:
- Unreachable Code: In functions like
home_timeline,user_blooms, andhashtag, did you notice that the secondreturnstatement is placed right after the first one? How might that affect whether_mark_rebloomed_by_meis ever executed? - Variable Definitions: In
self_profile(), areprofile_userandprofile_usernamedefined before they are used infollowersandblooms.get_blooms_for_user()?
There was a problem hiding this comment.
-
Again, I don't see repeated return statements.
-
Did you mean
other_profile?self_profiledoes not use those variables. Inother_profile, the variables are defined beforehand.profile_usernameis a route parameter. Forprofile_user, there is a check for None before proceeding with the rest of the code.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Clean styling! Just consider using a CSS variable for the green border and ensure display: flex is set on the footer.
There was a problem hiding this comment.
Clean and well-structured HTML template! Just remove the duplicate comments and ensure you use cloneNode(true) when instantiating it.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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().
There was a problem hiding this comment.
Good start! Have you considered adding ignores for your Python (venv, __pycache__, .env) and Node (node_modules, dist) environments?
…leErrorDialog functino
Only refetch if user in own profile or timeline as the rebloom will need to be shown at the top of the list of blooms. Otherwise, there's no need to fetch.
takanocap
left a comment
There was a problem hiding this comment.
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
| function refreshRouteData() { | ||
| const hash = window.location.hash.substring(1) || "/"; | ||
|
|
||
| if (hash.startsWith("/bloom/")) { |
There was a problem hiding this comment.
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 ?
| // 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]); |
There was a problem hiding this comment.
if this a fire and forget is clearer to use "void" on line 22 and other calls without .catch()?
|
|
||
| const href = link.getAttribute("href"); | ||
| // Only handle internal links (starting with / and not # anchors) | ||
| if (href && href.startsWith("/") && !href.startsWith("#")) { |
There was a problem hiding this comment.
is there a missing replacement field here or its meant to be a normal string?
|
|
||
| # Sort by timestamp (newest first) | ||
| # Sort by timestamp of rebloom or timestamp of creation (newest first) | ||
| sorted_blooms = list( |
Learners, PR Template
Self checklist
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:
Fetches blooms on navigation to a page, as stale cache was an issue.