Skip to content
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

Synchronize creation of Events and Authors #632

Merged
merged 10 commits into from
Nov 17, 2023
Merged

Conversation

mplorentz
Copy link
Member

This fixes #446 as well as some problems @martindsq was having with the stories/read branch. It's a different manifestation of the issue described in #385 where we were creating two identical Event records in different threads. In the past we fixed these by ensuring that the two duplicate events were merged into one when the context was saved. This results in one Event on disk, but the two Events in memory would still have different NSManagedObjectIDs until reloaded from the store. This breaks SwiftUI's observation code, meaning that if you were viewing a note or profile for the first time SwiftUI might be observing an objectID that never gets updated even after we download the relevant data from the network.

I fixed it by moving all Event and Author creation onto a single context. It was hard to do this elegantly without needing to pass two contexts (one for creation and one for processing, editing, etc.) all around the app. In the end I used @dependency injection to get the creation context into the creation functions, which meant I needed to change them from class to instance functions. It's a little janky, but I think this is much preferable to the confusion and possible developer errors it would cause to be passing two contexts around.

@mplorentz mplorentz requested a review from martindsq November 10, 2023 16:26
@mplorentz
Copy link
Member Author

I found a Core Data threading issue while running the unit tests with the Nos Diagnostics scheme. I'll get it fixed and update the PR.

@mplorentz mplorentz marked this pull request as draft November 10, 2023 19:01
@mplorentz
Copy link
Member Author

I fixed the threading issues but now the unit tests, specifically the SocialGrapheCache tests are taking forever to execute 🤔

@mplorentz
Copy link
Member Author

It turns out using an in-memory persistent store was causing the SocialGraphTests to take a long time. I couldn't figure out why so I switched to using an on-disk store for those. This is now ready for review.

@mplorentz mplorentz marked this pull request as ready for review November 14, 2023 16:24
@mplorentz mplorentz merged commit 2518aa0 into main Nov 17, 2023
2 of 3 checks passed
@mplorentz mplorentz deleted the fix-duplicate-events branch November 17, 2023 15:15
mplorentz added a commit that referenced this pull request Dec 1, 2023
@mplorentz mplorentz mentioned this pull request Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix reposts not loading
2 participants