Skip to content

Conversation

@crazytonyli
Copy link
Contributor

Changes

Given there is no major issue found in the ContainerContextFactory, we can now migrate to use the new Core Data stack fully. This PR removes the legacy Core Data stack (LegacyContextFactory) and merge ContainerContextFactory into ContextManager.

This PR also translates ContextManager to Swift, so that we can use all the nice things Swift provides us in the very foundation of our Core Data stack.

Regression Notes

  1. Potential unintended areas of impact
    None.

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    None.

  3. What automated tests I added (or what prevented me from doing so)
    None.

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@crazytonyli crazytonyli added the Core Data Issues related to Core Data label Dec 12, 2022
@crazytonyli crazytonyli added this to the 21.5 milestone Dec 12, 2022
@crazytonyli crazytonyli requested a review from a team December 12, 2022 21:39
@crazytonyli crazytonyli self-assigned this Dec 12, 2022
@peril-wordpress-mobile
Copy link

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Dec 12, 2022

You can test the changes in WordPress from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr19770-1e1d18e on your iPhone

If you need access to App Center, please ask a maintainer to add you.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Dec 12, 2022

You can test the changes in Jetpack from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr19770-1e1d18e on your iPhone

If you need access to App Center, please ask a maintainer to add you.

startupEvent.add(error: error)
}

// TODO: The original Objective C implement calls `loadPersistentStores` again here, but throws an exception regardless the result.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

❓ I can certainly keep the code that calls loadPersistentStores again, but I don't see how this additional call is necessary, did I miss anything?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see how this additional call is necessary

Me neither.

#import "PostService.h"
#import "TodayExtensionService.h"
#import "ContextManager.h"
#import "CoreDataStack.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this import is duplicated from line 5.

Suggested change
#import "CoreDataStack.h"

import Foundation
import CoreData

///A constant representing the current version of the data model.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
///A constant representing the current version of the data model.
/// A constant representing the current version of the data model.

@@ -1,5 +1,7 @@
import XCTest

Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Does this empty line signifies something or can we remove it?

Suggested change

Comment on lines 113 to 114
/// Ensure that the `context`'s concurrency type is not `confinementConcurrencyType`, since it will crash if `perform` or `performAndWait` is called.
guard context.concurrencyType == .mainQueueConcurrencyType || context.concurrencyType == .privateQueueConcurrencyType else {
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment says we want to check that the context != x. The code checks that == y || == z.

The difference might be important. I think it would be good to keep code and comment consistent.

Also, nitpick, /// will result in a documentation header comment, but that doesn't apply for this kind of comment since it's not on a definition but on a guard statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original PR chose to not reference the deprecated confinementConcurrencyType to avoid a warning.

Comment on lines +115 to +116
block()
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Is running the given block a fallback mechanism to keep the app working without having to do deal with the runtime complexity of handling an error if the context is incorrect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling performBlock on a context whose concurrency type is confinement crashes, see the original PR for context.

startupEvent.add(error: error)
}

// TODO: The original Objective C implement calls `loadPersistentStores` again here, but throws an exception regardless the result.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see how this additional call is necessary

Me neither.

@mokagio
Copy link
Contributor

mokagio commented Dec 15, 2022

Given there is no major issue found in the ContainerContextFactory, we can now migrate to use the new Core Data stack fully.

For breadcrumbs, see #19433 where we switched to use the new Core Data stack via feature toogle. That code has been running in production for more than a month.

@crazytonyli crazytonyli merged commit 0ffb6a0 into trunk Dec 19, 2022
@crazytonyli crazytonyli deleted the remove-legacy-context-factory branch December 19, 2022 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Core Data Issues related to Core Data

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants