Skip to content

Refactor UploadToShelfService to use UserRepository for shelf data assembly#11617

Closed
dogi wants to merge 1 commit intomasterfrom
refactor-upload-to-shelf-service-9091401644095974310
Closed

Refactor UploadToShelfService to use UserRepository for shelf data assembly#11617
dogi wants to merge 1 commit intomasterfrom
refactor-upload-to-shelf-service-9091401644095974310

Conversation

@dogi
Copy link
Member

@dogi dogi commented Mar 2, 2026

This pull request moves the logic for assembling shelf data out of UploadToShelfService and into the more appropriate UserRepository.

This abstracts away raw Realm instance operations from the service class, utilizing internal repository methods for RealmMeetup and RealmRemovedLog queries.


PR created automatically by Jules for task 9091401644095974310 started by @dogi

…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>
@google-labs-jules
Copy link
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@dogi dogi added the triage Further information is requested label Mar 2, 2026
Copy link
Collaborator

@Okuro3499 Okuro3499 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changes requested triage Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants