-
Notifications
You must be signed in to change notification settings - Fork 211
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
Cache NSManagedObjectID instead of the CurrentUserDTO #3500
Conversation
Generated by 🚫 Danger |
let context = databaseContainer.viewContext | ||
if Thread.isMainThread { | ||
currentUserId = context.currentUser?.user.id | ||
} else { | ||
context.performAndWait { | ||
currentUserId = context.currentUser?.user.id | ||
} | ||
databaseContainer.backgroundReadOnlyContext.performAndWait { | ||
currentUserId = databaseContainer.backgroundReadOnlyContext.currentUser?.user.id | ||
} | ||
self.currentUserId = currentUserId |
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.
This looked odd that we have such check here, therefore I changed it around.
SDK Size
|
SDK Performance
|
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.
LGTM! ✅ Much better approach 👌
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.
LGTM ✅ There are some failing tests though that need checking.
SDK Size
|
… crashes when accessing the DTO
1749b7f
to
4cda4ec
Compare
Quality Gate passedIssues Measures |
QA was done with @testableapple |
🔗 Issue Links
Resolves IOS-21
🎯 Goal
Cache
NSManagedObjectID
instead of the fullCurrentUserDTO
for increased reliability.📝 Summary
NSManagedObjectID
which is less susceptible to possible threading issues (although I haven't found out that his is actually the case, but something seems to have corrupted the DTO in rare cases)🛠 Implementation
We have seen a crash when NSManagedObjectContext's currentUser property is accessed which leads to a crash when the
user.id
is called. This PR tries to fix this issue by not keeping the DTO alive all the time and instead asking context to retrieve it instead of (which is not slow).I measured the time taken for accessing the
currentUser
property and when all the call sites are combined, it was 1 ms.🧪 Manual Testing Notes
Quick testing round of logging in and out
☑️ Contributor Checklist