-
-
Notifications
You must be signed in to change notification settings - Fork 146
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
Update presence_change migration for JSON to Protobuf conversion #1075
Conversation
WalkthroughThe changes in this pull request involve modifications to the Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
migrations/v0.5.6/migrate-presence-change.go (1)
88-88
: Rename variablebytes
toencodedPresenceChange
for clarityFor better readability, consider renaming the variable
bytes
toencodedPresenceChange
to clearly reflect its purpose.Apply this change:
- bytes, err := database.EncodePresenceChange(p) + encodedPresenceChange, err := database.EncodePresenceChange(p)And update its usage in the update operation:
operation = mongo.NewUpdateOneModel().SetFilter(bson.M{ "_id": doc["_id"], }).SetUpdate(bson.M{ "$set": bson.M{ - "presence_change": bytes, + "presence_change": encodedPresenceChange, }, })
p := &innerpresence.PresenceChange{} | ||
err := json.Unmarshal([]byte(presenceChangeStr), p) | ||
if err != nil { | ||
return fmt.Errorf("unmarshal presence change: %w", err) | ||
} | ||
|
||
bytes, err := database.EncodePresenceChange(p) | ||
if err != nil { | ||
return fmt.Errorf("encode error: %w", err) | ||
} |
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.
🛠️ Refactor suggestion
Handle individual document errors to prevent migration interruption
Currently, if an error occurs while unmarshaling or encoding a single document's presence change, the entire migration process stops. To enhance robustness, consider logging the error for that document and continuing with the rest of the batch. This ensures that one malformed document doesn't halt the entire migration.
Apply the following changes to handle errors individually:
if err != nil {
- return fmt.Errorf("unmarshal presence change: %w", err)
+ fmt.Printf("Warning: failed to unmarshal presence change for document %v: %v\n", doc["_id"], err)
+ continue
}
if err != nil {
- return fmt.Errorf("encode error: %w", err)
+ fmt.Printf("Warning: failed to encode presence change for document %v: %v\n", doc["_id"], err)
+ continue
}
Committable suggestion skipped: line range outside the PR's diff.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1075 +/- ##
=======================================
Coverage 46.79% 46.79%
=======================================
Files 84 84
Lines 12219 12219
=======================================
Hits 5718 5718
Misses 5928 5928
Partials 573 573 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
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.
Thanks for your contribution.
What this PR does / why we need it:
The main codebase has been updated to use Protobuf instead of JSON for encoding presence_change data. This migration script converts existing presence_change data from JSON to Protobuf format to match this change.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation:
Checklist:
Summary by CodeRabbit
New Features
Bug Fixes