-
-
Notifications
You must be signed in to change notification settings - Fork 29
London | SDC-25-July | Eyuel Abraham | Sprint1 | Feature/rebloom #59
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
base: main
Are you sure you want to change the base?
Changes from all commits
bdbb87d
8c91cb3
0019ce4
136d529
dbcbdfd
409a8ca
181346d
c7a56f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| from typing import Dict, Union | ||
| from data import blooms | ||
| from data.follows import follow, get_followed_usernames, get_inverse_followed_usernames | ||
| from data.follows import follow, get_followed_usernames, get_inverse_followed_usernames, unfollow | ||
| from data.users import ( | ||
| UserRegistrationError, | ||
| get_suggested_follows, | ||
|
|
@@ -150,6 +150,23 @@ def do_follow(): | |
| ) | ||
|
|
||
|
|
||
| @jwt_required() | ||
| def do_unfollow(unfollow_username): | ||
| current_user = get_current_user() | ||
| unfollow_user = get_user(unfollow_username) | ||
|
|
||
| if unfollow_user is None: | ||
| return make_response( | ||
| (f"Cannot unfollow {unfollow_username} - user does not exist", 404) | ||
| ) | ||
|
|
||
| unfollow(current_user, unfollow_user) | ||
| return jsonify( | ||
| { | ||
| "success": True, | ||
| } | ||
| ) | ||
|
|
||
| @jwt_required() | ||
| def send_bloom(): | ||
| type_check_error = verify_request_fields({"content": str}) | ||
|
|
@@ -228,6 +245,37 @@ def suggested_follows(limit_str): | |
| return jsonify(suggestions) | ||
|
|
||
|
|
||
| def update_rebloom_counter(bloom_id): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem like a public endpoint we should be exposing? Anyone could make it look like a particular bloom has millions of reblooms by just calling this endpoint themselves? |
||
| try: | ||
| id_int = int(bloom_id) | ||
| except ValueError: | ||
| return make_response((f"Invalid bloom id", 400)) | ||
| blooms.update_rebloom_counter(id_int) | ||
| return jsonify( | ||
| { | ||
| "success": True, | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| @jwt_required() | ||
| def send_rebloom(): | ||
| user = get_current_user() | ||
| bloom_id = request.json["id"] | ||
| try: | ||
| id_int = int(bloom_id) | ||
| except ValueError: | ||
| return make_response((f"Invalid bloom id", 400)) | ||
| blooms.add_rebloom(sender=user, id=id_int) | ||
|
|
||
| return jsonify( | ||
| { | ||
| "success": True, | ||
| } | ||
| ) | ||
|
|
||
|
|
||
|
|
||
| def hashtag(hashtag): | ||
| return jsonify(blooms.get_blooms_with_hashtag(hashtag)) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,9 @@ CREATE TABLE blooms ( | |
| id BIGSERIAL NOT NULL PRIMARY KEY, | ||
| sender_id INT NOT NULL REFERENCES users(id), | ||
| content TEXT NOT NULL, | ||
| send_timestamp TIMESTAMP NOT NULL | ||
| send_timestamp TIMESTAMP NOT NULL, | ||
| reblooms INT NOT NULL DEFAULT 0, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This database structure leads to a race condition where you need to remember to increment/decrement reblooms when someone adds/removes a rebloom, and where there may be a window between adding/removing the bloom and incrementing/decrementing the counter where those values are inconsistent. Instead, can you work out how you can derive the reblooms count when SELECTing, maybe by using a JOIN in your SQL, rather than needing to store it in the row? |
||
| original_bloom_id BIGINT REFERENCES blooms(id) | ||
| ); | ||
|
|
||
| CREATE TABLE follows ( | ||
|
|
||
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.
This change looks unrelated? Please remove