Populate last access data in admin user details#435
Populate last access data in admin user details#435
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughThe pull request optimizes device retrieval in the UsersResource endpoint by introducing repository-level joined queries. Two new repository methods— Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
backend/src/main/java/org/cryptomator/hub/entities/Device.java (1)
167-176: Consider using a typed projection for type safety.The
Object[]return type requires unchecked casts at the call site. A typed record could make the API clearer and catch misuse at compile time:💡 Optional: Use a typed record for the result
public record DeviceWithLastAccess(Device device, VaultKeyRetrievedEvent lastAccessEvent) {} public List<DeviceWithLastAccess> findByOwnerWithLastAccess(String userId) { return getEntityManager().createQuery(""" SELECT d, e FROM Device d LEFT JOIN VaultKeyRetrievedEvent e ON e.deviceId = d.id AND e.id = (SELECT MAX(e2.id) FROM VaultKeyRetrievedEvent e2 WHERE e2.deviceId = d.id) WHERE d.owner.id = :userId """, Object[].class) .setParameter("userId", userId) .getResultStream() .map(row -> new DeviceWithLastAccess((Device) row[0], (VaultKeyRetrievedEvent) row[1])) .toList(); }This is optional since the current implementation is functionally correct and the casting is isolated to the repository layer.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/src/main/java/org/cryptomator/hub/entities/Device.java` around lines 167 - 176, Replace the raw Object[] projection returned by Device.findByOwnerWithLastAccess with a typed projection: add a record DeviceWithLastAccess(Device device, VaultKeyRetrievedEvent lastAccessEvent) and change findByOwnerWithLastAccess to run the same JPQL query but request Object[].class, stream the results, map each Object[] row to new DeviceWithLastAccess((Device)row[0], (VaultKeyRetrievedEvent)row[1]) and return List<DeviceWithLastAccess>; keep the same parameter binding and query text in getEntityManager().createQuery(...) and use getResultStream().map(...).toList() for the conversion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@backend/src/main/java/org/cryptomator/hub/entities/Device.java`:
- Around line 167-176: Replace the raw Object[] projection returned by
Device.findByOwnerWithLastAccess with a typed projection: add a record
DeviceWithLastAccess(Device device, VaultKeyRetrievedEvent lastAccessEvent) and
change findByOwnerWithLastAccess to run the same JPQL query but request
Object[].class, stream the results, map each Object[] row to new
DeviceWithLastAccess((Device)row[0], (VaultKeyRetrievedEvent)row[1]) and return
List<DeviceWithLastAccess>; keep the same parameter binding and query text in
getEntityManager().createQuery(...) and use getResultStream().map(...).toList()
for the conversion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b3d6d35f-0f40-4063-9ab5-4bd52d333bf7
📒 Files selected for processing (4)
backend/src/main/java/org/cryptomator/hub/api/UsersResource.javabackend/src/main/java/org/cryptomator/hub/entities/Device.javabackend/src/main/java/org/cryptomator/hub/entities/LegacyDevice.javabackend/src/main/java/org/cryptomator/hub/entities/User.java
| }); | ||
| } | ||
|
|
||
| public List<Object[]> findByOwnerWithLastAccess(String userId) { |
There was a problem hiding this comment.
please replace Object[] by a dedicated type (record)
There was a problem hiding this comment.
please explain this change - seems unrelated and changes behaviour in different places
There was a problem hiding this comment.
I initially removed the eager fetch to avoid loading devices twice, once in findByIdWithEagerDetails and again via the new findByOwnerWithLastAccess queries. But you're right, this method is shared and the change would affect other callers. Reverted.
Summary