Closed
Conversation
mdryankov
reviewed
Jan 16, 2023
Comment on lines
+692
to
+698
| func (m *database) applyReactionsChecks(reactions *collectionWrapper) error { | ||
| log.Println("apply reactions checks.....") | ||
|
|
||
| log.Println("reactions checks passed") | ||
| return nil | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
Adding indexes is a mandatory step. Please add the necessary indexes here. Notice the need of composite indexes as well
Comment on lines
+1554
to
+1562
| primitive.E{Key: "$inc", Value: bson.D{ | ||
| primitive.E{Key: "reaction_stats." + reaction, Value: incrementValue}, | ||
| }}, |
Comment on lines
+25
to
+34
| type AggregateReactions struct { | ||
| ID string `json:"id" bson:"_id"` | ||
| PostID string `json:"post_id" bson:"post_id"` | ||
| Reactions Reaction `json:"reactions" bson:"reactions"` | ||
| } | ||
|
|
||
| type Reaction struct { | ||
| Key *string `json:"k" bson:"k"` | ||
| Value *string `json:"v" bson:"v"` | ||
| } |
Collaborator
Author
There was a problem hiding this comment.
You are right I forgot to clean this up. I will remove. Thank you!
Comment on lines
+97
to
+108
| //take the count of the total thumbs up reactions | ||
| filter := bson.M{"_id": postID} | ||
| update := bson.D{ | ||
| {"$set", bson.D{{"reaction_stats.thumbs-up", len(list[i].Reactions["thumbs-up"])}}}, | ||
| {"$unset", bson.D{{"reactions", ""}}}, | ||
| } | ||
|
|
||
| _, err := sa.db.posts.UpdateOne(filter, update, nil) | ||
| if err != nil { | ||
| fmt.Printf("error migrating reactions %s", err) | ||
| return fmt.Errorf("error migrating reactions %s", err) | ||
| } |
Contributor
There was a problem hiding this comment.
This looks unfinished and hardcoded. Also I think it should be moved to driven/storage/database.go where prior migrations are implemented.
Comment on lines
+473
to
+507
| func (sa *Adapter) DeleteUserPostReactions(context TransactionContext, clientID string, userID string) error { | ||
|
|
||
| filter := bson.M{"user_id": userID} | ||
|
|
||
| var res []model.PostReactions | ||
| err := sa.db.reactions.Find(filter, &res, nil) | ||
| if err != nil { | ||
| log.Printf("error deleting reactions for user %s - %s", userID, err.Error()) | ||
| return err | ||
| } | ||
|
|
||
| _, err = sa.db.reactions.DeleteMany(filter, nil) | ||
| if err != nil { | ||
| log.Printf("error deleting user reactions to post - %s", err.Error()) | ||
| return err | ||
| } | ||
|
|
||
| for i := 0; i < len(res); i++ { | ||
| for j := 0; j < len(res[i].Reactions); j++ { | ||
| err = sa.UpdateReactionStats(res[i].PostID, false, res[i].Reactions[j]) | ||
| if err != nil { | ||
| return fmt.Errorf("error decrementing reaction stats for post %s with reaction %s for %s: %v", res[i].PostID, res[i].Reactions[j], userID, err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
When a transaction is used, then all sub operations must be incorporated in the transaction.
Comment on lines
+1530
to
1541
| opts := options.Update().SetUpsert(true) | ||
| _, err := sa.db.reactions.UpdateOne(filter, update, opts) | ||
|
|
||
| res, err := sa.db.posts.UpdateOneWithContext(context, filter, update, nil) | ||
| if err != nil { | ||
| return fmt.Errorf("error updating post %s with reaction %s for %s: %v", postID, reaction, userID, err) | ||
| } |
Contributor
There was a problem hiding this comment.
Same comment related for transaction wrapping as above.
255e45b to
1af4fdc
Compare
Collaborator
|
Closing this due to outdated changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Please provide a summary of the pull request and the issue it resolves. Please add necessary details, context, dependencies, explanation of when review is needed (see next section), etc.
This PR is refactoring reactions in order to fix #308 as there was no way to delete reactions with current setup. Reactions will now be more robust allowing users to have multiple reactions to a post and no code changes for any new type of reactions.
**Resolves #325 **
Review Time Estimate
Please give your idea of how soon this pull request needs to be reviewed by selecting one of the options below. This can be based on the criticality of the issue at hand and/or other relevant factors.
Type of changes
Please select a relevant option:
Checklist:
Please select all applicable options: