-
Notifications
You must be signed in to change notification settings - Fork 0
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
Adds comments #42
base: main
Are you sure you want to change the base?
Adds comments #42
Conversation
76d9dd5
to
179c08a
Compare
pub id: ObjectId, | ||
pub owner: ObjectId, | ||
pub parent_post: ObjectId, | ||
pub parent_comments: Vec<ObjectId>, |
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.
What is parent_comments
?
179c08a
to
13f0053
Compare
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.
How does the randomness work? Is that documented somewhere?
@@ -69,6 +73,51 @@ async fn initialize_database(db: &Database) -> mongodb::error::Result<()> { | |||
.build(), | |||
None, | |||
), | |||
// Is this too many indices? Probably... |
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.
Yep
// Is this too many indices? Probably... |
@@ -69,6 +73,51 @@ async fn initialize_database(db: &Database) -> mongodb::error::Result<()> { | |||
.build(), | |||
None, | |||
), | |||
// Is this too many indices? Probably... | |||
comments.create_index( | |||
IndexModel::builder().keys(doc! {"parent_post": -1}).build(), |
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.
The direction of single-key indexes doesn’t matter, so use 1
for consistency.
IndexModel::builder().keys(doc! {"parent_post": -1}).build(), | |
IndexModel::builder().keys(doc! {"parent_post": 1}).build(), |
comments.create_index( | ||
IndexModel::builder() | ||
.keys(doc! {"absolute_score": -1}) | ||
.build(), | ||
None, | ||
), |
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.
Only need an index in one direction.
comments.create_index( | |
IndexModel::builder() | |
.keys(doc! {"absolute_score": -1}) | |
.build(), | |
None, | |
), |
), | ||
comments.create_index( | ||
IndexModel::builder() | ||
.keys(doc! {"sequential_id": -1}) |
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.
.keys(doc! {"sequential_id": -1}) | |
.keys(doc! {"sequential_id": 1}) |
} | ||
|
||
// If the comment is trying to be nested too deep, send a 400 Bad Request. | ||
if request.parent_comments.len() > conf::COMMENT_MAX_DEPTH { |
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.
We shouldn’t be trusting the client to send the correct path. Can we store just the parent id instead of the whole list of ancestor ids? I’m not clear on what that’s used for, other than the depth check.
Co-authored-by: Ryan O’Hara <[email protected]>
308cdc0
to
b36e4ef
Compare
New features
GET /comments/
for fetching comments from either a post or another comment. Allows you to sort by: newest, top, worst, most controversial, overall best, and most replies.POST /comments/
for creating a comment as either a direct reply to the post, or a reply to another comment.DELETE /comments/{comment_id}/
for deleting a comment. A deleted comment will be rendered with text "[deleted]" to indicate it's been deleted, but also not totally removed from the database so the threaded tree structure is not destroyed.PUT /comments/{comment_id}/vote
for voting on a comment.Old changes/updates
impl
to theMaskedObjectId
struct
to help with threaded comment sorting.get_trending_score_time
method into its own file, as I'm now using it for comments as well as posts."votes"
collection into"comment_votes"
and"post_votes"
collections. This was because I added votes for comments and thought comment votes and post votes should be stored separately.Docs
openapi.yaml
docs for routes:GET /comments/
,POST /comments/
,DELETE /comments/{comment_id}/
, andPUT /comments/{comment_id}/vote
.Notes
Closes #15, #16, #17, and #19.