-
Notifications
You must be signed in to change notification settings - Fork 83
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
chore(users): migrate proto backend to native #1805
base: 01-29-chore_users_delete_old_worker_code
Are you sure you want to change the base?
chore(users): migrate proto backend to native #1805
Conversation
Deploying rivet with
|
Latest commit: |
6b956b2
|
Status: | ✅ Deploy successful! |
Preview URL: | https://fc1263c2.rivet.pages.dev |
Branch Preview URL: | https://01-07-chore-users-migrate-pr.rivet.pages.dev |
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
ec88581
to
d8bc66a
Compare
29b15a5
to
73890c0
Compare
d8bc66a
to
6fb3d05
Compare
73890c0
to
20d844f
Compare
6fb3d05
to
c1c6586
Compare
20d844f
to
fd3c4de
Compare
c1c6586
to
2c153f0
Compare
fd3c4de
to
e3a441c
Compare
2c153f0
to
b259e38
Compare
e3a441c
to
e3632e7
Compare
b259e38
to
9a2121e
Compare
e3632e7
to
7e75cf3
Compare
9a2121e
to
2519b6f
Compare
7e75cf3
to
4bfdbf2
Compare
2519b6f
to
be1bf74
Compare
4bfdbf2
to
fe3ab7c
Compare
be1bf74
to
936d97d
Compare
18a7d75
to
764ba21
Compare
8b00f39
to
a082694
Compare
764ba21
to
31ed4b4
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.
PR Summary
This PR migrates user identity handling from proto backend types to native Rust types across the codebase. Here's a summary of the key changes:
- Added new native types in
/packages/services/user/src/types/identity.rs
andmod.rs
to replace proto backend user types - Moved URL generation functions
user_profile
anduser_avatar
fromutil/core/src/route.rs
toservices/user/src/route.rs
- Updated identity creation and validation logic in
user/src/ops/identity/create.rs
to use native types instead of proto types - Simplified UUID comparisons by removing unnecessary proto type conversions in multiple files
- Added new workspace dependencies
util
andtypes-proto
inuser/Cargo.toml
to support the migration
Key points to review:
- Verify URL construction safety in the new
user/src/route.rs
functions - Check error handling consistency with
::
scope resolution operator inprofile_validate.rs
- Ensure proper type safety in UUID comparisons after removing proto type conversions
- Review test coverage for the new native type implementations
- Consider documenting the migration pattern for future similar changes
26 file(s) reviewed, 13 comment(s)
Edit PR Review Bot Settings | Greptile
a082694
to
6de4e36
Compare
31ed4b4
to
1f6a1b5
Compare
6de4e36
to
a69da5b
Compare
1f6a1b5
to
6b956b2
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.
PR Summary
Based on the provided files and previous review, I'll focus on the most recent changes in this PR that weren't covered in the previous summary.
This PR continues the migration of user identity handling from proto backend to native Rust types, with several important updates:
- Migrated context handling in API routes from
ctx.op_ctx()
to&*ctx
for more idiomatic Rust usage - Updated
ApiCtx
usage in fetch functions acrossconvert/src/fetch/
modules to align with native implementation - Simplified user ID handling by removing unnecessary unwrapping and proto type conversions
- Streamlined operation calls by using
ctx.op
directly instead ofchirp_workflow::compat::op
Key points to review:
- Ensure consistent error propagation with the new context dereferencing pattern
- Verify that all
ApiCtx
conversions maintain proper transaction boundaries - Check for potential memory leaks in the new context handling approach
- Consider adding documentation for the new context usage patterns
The changes maintain the same functionality while making the code more idiomatic and reducing complexity in the type system.
31 file(s) reviewed, 11 comment(s)
Edit PR Review Bot Settings | Greptile
@@ -29,9 +29,9 @@ pub async fn list( | |||
) -> GlobalResult<models::CloudGamesGetGamesResponse> { | |||
let accessible_games = ctx.auth().accessible_games(ctx.op_ctx()).await?; |
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.
style: Consider updating ctx.auth().accessible_games(ctx.op_ctx())
to use the new context style for consistency
let ban_ts = unwrap!(team_bans | ||
.banned_users | ||
.iter() | ||
.find(|ban| user.user_id == ban.user_id) | ||
.find(|ban| Some(user.user_id.into()) == ban.user_id) | ||
).ban_ts; |
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.
style: consider using unwrap_with! here to provide a more descriptive error message if the ban is not found
@@ -53,7 +53,7 @@ async fn get_profile( | |||
_watch_index: WatchIndexQuery, | |||
) -> GlobalResult<(models::IdentityProfile, i64)> { | |||
let identities = | |||
fetch::identity::profiles(ctx.op_ctx(), current_user_id, vec![identity_id]).await?; | |||
fetch::identity::profiles(&*ctx, current_user_id, vec![identity_id]).await?; |
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.
style: dereferencing ctx with &* could potentially cause issues if the Deref implementation for Ctx<Auth> changes in the future. Consider using an explicit conversion method instead.
@@ -87,7 +87,7 @@ pub async fn handles( | |||
); | |||
|
|||
let identities = | |||
fetch::identity::handles(ctx.op_ctx(), current_user_id, query.identity_ids).await?; | |||
fetch::identity::handles(&*ctx, current_user_id, query.identity_ids).await?; |
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.
style: same dereferencing pattern used here - should be consistent with how context is handled across the codebase
@@ -120,7 +120,7 @@ pub async fn summaries( | |||
// Wait for an update if needed | |||
|
|||
let identities = | |||
fetch::identity::summaries(ctx.op_ctx(), current_user_id, query.identity_ids).await?; | |||
fetch::identity::summaries(&*ctx, current_user_id, query.identity_ids).await?; |
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.
logic: consider adding error handling for the case where identities.into_iter().next() returns None, rather than just using unwrap_with
game_ids: Vec<common::Uuid>, | ||
) -> GlobalResult<(game::get::Response, HashMap<Uuid, backend::team::Team>)> { |
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.
logic: The function accepts Vec<common::Uuid> but returns HashMap<Uuid, ...> - ensure these UUID types are compatible across the codebase
let (users, teams_ctx, linked_accounts) = tokio::try_join!( | ||
users(ctx, raw_user_ids.clone()), | ||
teams(ctx, user_ids.clone()), | ||
linked_accounts(ctx, user_ids.clone()), | ||
teams(ctx, raw_user_ids.clone()), | ||
linked_accounts(ctx, raw_user_ids.clone()), | ||
)?; |
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.
style: Cloning raw_user_ids three times could be inefficient. Consider cloning once before the try_join and reusing the cloned vector.
pub struct Email { | ||
pub email: String, | ||
} |
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.
style: Consider adding validation for email format and length. Email strings should be validated before storage.
impl From<&Identity> for backend::user_identity::Identity { | ||
fn from(identity: &Identity) -> Self { | ||
backend::user_identity::Identity { | ||
kind: Some(match &identity.kind { | ||
Kind::Email(kind) => { | ||
backend::user_identity::identity::Kind::Email( | ||
backend::user_identity::identity::Email { | ||
email: kind.email.clone() | ||
} | ||
) | ||
} | ||
Kind::DefaultUser(_) => { | ||
backend::user_identity::identity::Kind::DefaultUser( | ||
backend::user_identity::identity::DefaultUser {} | ||
) | ||
} | ||
}) | ||
} | ||
} | ||
} |
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.
style: Consider implementing TryFrom instead of From to handle potential validation errors during conversion.
kind: Some(match &identity.kind { | ||
Kind::Email(kind) => { | ||
backend::user_identity::identity::Kind::Email( | ||
backend::user_identity::identity::Email { | ||
email: kind.email.clone() | ||
} |
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.
style: Consider adding error handling for the case where email is empty or invalid during conversion.
Changes