@@ -41,14 +41,22 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
4141 private func upsertApp(
4242 bundleID: String ,
4343 entitlements: Entitlements ,
44- isFreeTeam: Bool ,
45- appIDs: [ String : Components . Schemas . BundleId ]
44+ isFreeTeam: Bool
4645 ) async throws -> Components . Schemas . BundleId {
46+ let newBundleID = ProvisioningIdentifiers . identifier ( fromSanitized: bundleID, context: self . context)
47+
48+ let existing = try await context. developerAPIClient
49+ . bundleIdsGetCollection ( query: . init(
50+ filter_lbrack_identifier_rbrack_: [ bundleID]
51+ ) )
52+ . ok. body. json. data
53+ // filter[identifier] is a prefix filter so we need to manually upgrade to equality
54+ . first ( where: { $0. attributes? . identifier == newBundleID } )
55+
4756 let appID : Components . Schemas . BundleId
48- if let existing = appIDs [ bundleID ] {
57+ if let existing {
4958 appID = existing
5059 } else {
51- let newBundleID = ProvisioningIdentifiers . identifier ( fromSanitized: bundleID, context: self . context)
5260 let name = ProvisioningIdentifiers . appName ( fromSanitized: bundleID)
5361 let createResponse = try await context. developerAPIClient. bundleIdsCreateInstance (
5462 body: . json(
@@ -150,8 +158,7 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
150158 /// that the app has).
151159 private func addApp(
152160 _ app: URL ,
153- isFreeTeam: Bool ,
154- appIDs: [ String : Components . Schemas . BundleId ]
161+ isFreeTeam: Bool
155162 ) async throws -> ProvisioningInfo {
156163 let infoURL = app. appendingPathComponent ( " Info.plist " )
157164 guard let data = try ? Data ( contentsOf: infoURL) ,
@@ -179,7 +186,7 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
179186 entitlements = try Entitlements ( entitlements: [ ] )
180187 }
181188
182- let appID = try await upsertApp ( bundleID: bundleID, entitlements: entitlements, isFreeTeam: isFreeTeam, appIDs : appIDs )
189+ let appID = try await upsertApp ( bundleID: bundleID, entitlements: entitlements, isFreeTeam: isFreeTeam)
183190 let newBundleID = appID. attributes!. identifier!
184191
185192 let teamID = try signingInfo. certificate. teamID ( )
@@ -225,17 +232,6 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
225232 )
226233 }
227234
228- // keyed by sanitized bundle ID
229- private func getCurrentAppIDs( ) async throws -> [ String : Components . Schemas . BundleId ] {
230- let bundleIDs = try await context. developerAPIClient. bundleIdsGetCollection ( ) . ok. body. json. data
231- let keyedIDs = bundleIDs
232- . compactMap { id -> ( String , Components . Schemas . BundleId ) ? in
233- guard let bundleID = id. attributes? . identifier else { return nil }
234- return ( ProvisioningIdentifiers . sanitize ( identifier: bundleID) , id)
235- }
236- return Dictionary ( keyedIDs, uniquingKeysWith: { $1 } )
237- }
238-
239235 /// Registers the app + its extensions, returning the profile and entitlements of each
240236 public func perform( ) async throws -> [ URL : ProvisioningInfo ] {
241237 var apps : [ URL ] = [ root]
@@ -244,17 +240,15 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
244240 apps += plugins. implicitContents. filter { $0. pathExtension. lowercased ( ) == " appex " }
245241 }
246242
247- async let isFreeTeamTask = context. auth. team ( ) ? . isFree == true
248- async let appIDsTask = getCurrentAppIDs ( )
249- let ( isFreeTeam, appIDs) = try await ( isFreeTeamTask, appIDsTask)
243+ let isFreeTeam = try await context. auth. team ( ) ? . isFree == true
250244
251245 return try await withThrowingTaskGroup (
252246 of: ( URL, ProvisioningInfo) . self,
253247 returning: [ URL : ProvisioningInfo ] . self
254248 ) { group in
255249 for app in apps {
256250 group. addTask {
257- let info = try await addApp ( app, isFreeTeam: isFreeTeam, appIDs : appIDs )
251+ let info = try await addApp ( app, isFreeTeam: isFreeTeam)
258252 return ( app, info)
259253 }
260254 }
0 commit comments