Migrate remaining Core Data writes to performAndSave

未关闭
#26,313 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
一周以上
新手友好度
42/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
活跃
技术栈
objective-c, swift
领域
database

调研方向

Start with the listed call sites, especially NotificationSyncMediator.swift, PostRepository.swift, MediaService.m, and PostTagService.m; read the surrounding code and the existing performAndSave API from #15830. Review each save to determine whether it can use performAndSave or must remain a main-context save, preserving intentional synchronous behavior and documenting those cases. Done means the listed legacy calls are migrated or intentionally retained with comments, and the old save APIs are deprecated.

由索引模型根据 Issue 内容生成。

描述

[Type] Tech Debt Core Data

Follow-up to #15830, which added performAndSave. That API is now the standard way to write to Core Data (about 180 non-test call sites), but some writes still use the older save calls on ContextManager / CoreDataStack, and a few call NSManagedObjectContext.save() directly. This issue tracks moving them over.

The sites below are a snapshot of trunk at e64c851c0d. Tests and mocks are not included.

Notes for whoever picks this up
  • Main-context saves: Many of these save the main context synchronously, and some do so on purpose. For example, NotificationSyncMediator uses saveContextAndWait to avoid animation glitches when pushing the details screen. performAndSave writes on a new background context, so it can't simply replace those calls. Decide site by site, and leave a short comment wherever a main-context save is intentional.
  • Direct context.save() calls: These skip ContextManager's error handling and its permanent-ID step (internalSave), so they are worth fixing even where the write stays on the main context.
  • Objective-C call sites: performAndSave: and performAndSave:completion:onQueue: are callable from Objective-C, so these sites can be migrated without moving to Swift first.
  • End state: Once the migration is complete (or only intentional main-context saves remain), mark saveContextAndWait(_:), save(_:) and save(_:completion:on:) as deprecated the way newDerivedContext() already is, so the old calls don't come back.
Out of scope
  • ContextManager+ErrorHandling.swift: the internalSave implementation itself
  • ShareExtensionCore/Data/SharedCoreDataStack.swift: the share extension's own stack
  • NullBlogPropertySanitizer.swift: a one-off cleanup during migration
Old ContextManager save calls (56 sites)

Modules/Sources/WordPressData/Swift/ReaderPost.swift

  • L23 — save(_:)

WordPress/Classes/Services/CommentService+Swift.swift

  • L85 — save(_:completion:on:)

WordPress/Classes/Services/Facades/BlogSyncFacade.m

  • L66 — saveContextAndWait

WordPress/Classes/Services/MediaImportService.swift

  • L99 — saveContextAndWait

WordPress/Classes/Services/MediaService.m

  • L99 — saveContext: (ObjC)
  • L131 — saveContext: (ObjC)
  • L148 — saveContext: (ObjC)
  • L207 — saveContext: (ObjC)
  • L218 — saveContext: (ObjC)
  • L359 — saveContext: (ObjC)
  • L506 — saveContext: (ObjC)

WordPress/Classes/Services/MenusService.m

  • L78 — saveContext: (ObjC)
  • L146 — saveContext: (ObjC)
  • L240 — saveContext: (ObjC)

WordPress/Classes/Services/NotificationSyncMediator.swift

  • L513`````` — saveContextAndWait

WordPress/Classes/Services/PostCoordinator.swift

  • L237 — saveContextAndWait
  • L294 — saveContextAndWait
  • L306 — saveContextAndWait

WordPress/Classes/Services/PostRepository.swift

  • L146 — saveContextAndWait
  • L166 — saveContextAndWait
  • L217 — saveContextAndWait
  • L277 — saveContextAndWait
  • L291 — saveContextAndWait
  • L296 — saveContextAndWait
  • L317 — saveContextAndWait
  • L331 — saveContextAndWait
  • L338 — saveContextAndWait

WordPress/Classes/Services/PostService+Revisions.swift

  • L28 — save(_:completion:on:)

WordPress/Classes/Services/PostService+UnattachedMedia.swift

  • L19```````` — save(_:)

WordPress/Classes/Services/PostTagService.m

  • L41 — saveContext: (ObjC)
  • L72 — saveContext: (ObjC)
  • L93 — saveContext: (ObjC)
  • L120 — saveContext: (ObjC)
  • L139 — saveContext: (ObjC)
  • L248 — saveContextAndWait
  • L268 — saveContextAndWait

WordPress/Classes/Services/Reader Post/ReaderPostService.m

  • L255````````` — saveContext: (ObjC)
  • L460`````````` — saveContext: (ObjC)

WordPress/Classes/ViewRelated/Blog/Sharing/SharingButtonsViewController.swift

  • L637``````````` — save(_:completion:on:)

WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/BlogListViewModel.swift

  • L71```````````` — saveContextAndWait
  • L76````````````` — save(_:)

WordPress/Classes/ViewRelated/Comments/Controllers/CommentDetailViewController.swift

  • L553`````````````` — saveContextAndWait

WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainDetails/ViewModel/RegisterDomainDetailsServiceProxy.swift

  • [L221](https://github.com/wordpress-mobile/WordPress-iOS/blob/e64c851c0dd17e57e64424dc1934d7ddad610984/WordPress/Classes/ViewRelated/Domains/Domain%20registration/RegisterDomainDetails/ViewModel/RegisterDomainDetailsServiceProxy.swift#L221) — save(_:)

WordPress/Classes/ViewRelated/Menus/Controllers/MenuItemsViewController.m

  • L98```````````````` — saveContext: (ObjC)
  • L870````````````````` — saveContextAndWait

WordPress/Classes/ViewRelated/Menus/Controllers/MenuPostService.m

  • L101`````````````````` — saveContext: (ObjC)

WordPress/Classes/ViewRelated/Menus/Controllers/MenusViewController.m

  • L383``````````````````` — saveContext: (ObjC)

WordPress/Classes/ViewRelated/Post/PostEditor+Publish.swift

  • L63```````````````````` — save(_:)
  • L239````````````````````` — saveContextAndWait
  • L345`````````````````````` — save(_:)

WordPress/Classes/ViewRelated/Post/PostEditor.swift

  • L168 — saveContextAndWait

WordPress/Classes/ViewRelated/Reader/Comments/ReaderCommentsViewController.swift

  • L271```````````````````````` — save(_:)

WordPress/Classes/ViewRelated/Reader/Controllers/ReaderStreamViewController.swift

  • L139````````````````````````` — save(_:)
  • L298`````````````````````````` — save(_:)
  • L916``````````````````````````` — save(_:)

WordPress/Classes/ViewRelated/Reader/Detail/ReaderDetailCoordinator.swift

  • L613```````````````````````````` — save(_:)
Direct NSManagedObjectContext.save() (8 sites)
  • WordPress/Classes/Services/SiteSuggestionService.swift L94 — try? ContextManager.shared.mainContext.save()
  • WordPress/Classes/Services/SuggestionService.swift L78 — try? blog.managedObjectContext?.save()
  • ['WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationsViewController/NotificationsViewController.swift' L1935](https://github.com/wordpress-mobile/WordPress-iOS/blob/e64c851c0dd17e57e64424dc1934d7ddad610984/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationsViewController/NotificationsViewController.swift#L1935) — try mainContext.save()
  • ['WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationsViewController/NotificationsViewModel.swift' L116](https://github.com/wordpress-mobile/WordPress-iOS/blob/e64c851c0dd17e57e64424dc1934d7ddad610984/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationsViewController/NotificationsViewModel.swift#L116) — try mainContext.save()
  • WordPress/Classes/ViewRelated/Reader/Controllers/ReaderHelpers.swift L131````````````````````````````````` — try? context.save()
  • WordPress/Classes/ViewRelated/Reader/Controllers/ReaderPostActions/ReaderBlockUserAction.swift L45`````````````````````````````````` — try context.save()
  • WordPress/Classes/ViewRelated/Reader/Controllers/ReaderPostBlockingController.swift L90``````````````````````````````````` — try? context.save()
  • WordPress/Classes/ViewRelated/Reader/Controllers/ReaderStreamViewController.swift L736```````````````````````````````````` — try? viewContext.save()

Generated by Claude Code

主要语言
Swift
星标
3.9k
派生
1.2k
平均合并
1 天 23 小时
30 天内合并 PR
136

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

wordpress-mobile/WordPress-iOS 的其他 Issue

查看 wordpress-mobile/WordPress-iOS 的全部 Issue

相似的 Issue

更多 Swift Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。