Refactor UploadToShelfService to use UserRepository for shelf data assembly#11617
Refactor UploadToShelfService to use UserRepository for shelf data assembly#11617
Conversation
…sembly 1. Added `getAllSyncableUsers()` suspend method to `UserRepository` returning unmanaged user copies with non-empty `_id`. 2. Added `buildShelfData(userId, serverShelfJson, myLibIds, myCourseIds)` suspend method to `UserRepository`, internalizing `getMyMeetUpIds` and `removedIds` helpers. 3. Updated `uploadToShelf` and `uploadSingleUserToShelf` in `UploadToShelfService` to call repository methods instead of passing raw Realm instances to helper functions. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Okuro3499
left a comment
There was a problem hiding this comment.
1. buildShelfData ignores its own userId parameter for _id (UserRepositoryImpl.kt:658)
// userId is passed in, but `_id` is set from SharedPreferences instead
`object`.addProperty("_id", settings.getString("userId", ""))
The method takes userId: String and uses it correctly for getMyMeetUpIds and removedIds, but then writes a different value — the SharedPreferences userId — as the JSON _id. This
replicates the original behaviour faithfully but it makes the parameter contract misleading and fragile. If model.id (passed as userId) ever differs from SharedPreferences'
userId, the shelf document gets the wrong _id. The parameter should either be used consistently or the method should be honest that it ignores it for _id.
2. getAllSyncableUsers name is broader than its query (UserRepositoryImpl.kt:103–111)
realm.where(RealmUser::class.java)
.isNotEmpty("_id")
.findAll()
This returns all users with a non-empty _id — including guests, pending users, and other types. The original inline query had the same scope, but naming it getAllSyncableUsers
implies semantics (sync-ready) that may invite misuse elsewhere. The filtering that actually gates behaviour (skipping guest users) happens in the caller. At minimum this should
be documented; ideally it's renamed to getAllUsersWithId to match what it actually does.
This pull request moves the logic for assembling shelf data out of
UploadToShelfServiceand into the more appropriateUserRepository.This abstracts away raw Realm instance operations from the service class, utilizing internal repository methods for
RealmMeetupandRealmRemovedLogqueries.PR created automatically by Jules for task 9091401644095974310 started by @dogi