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

Move refreshCheckout out of db transaction #2379

Merged
merged 1 commit into from
May 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 30 additions & 44 deletions Sources/App/Commands/Analyze.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,7 @@ extension Analyze {
) { group in
for pkg in packages {
group.addTask {
let result = try await database.transaction { tx in
// Wrap in a Result to avoid throwing out of the transaction, causing a roll-back
await Result {
try await analyze(client: client,
transaction: tx,
logger: logger,
package: pkg)
}
}
try result.get()

try await analyze(client: client, database: database, logger: logger, package: pkg)
return pkg
}
}
Expand All @@ -207,51 +197,47 @@ extension Analyze {


static func analyze(client: Client,
transaction: Database,
database: Database,
logger: Logger,
package: Joined<Package, Repository>) async throws {
try refreshCheckout(logger: logger, package: package)
try await updateRepository(on: transaction, package: package)

let versionDelta = try await diffVersions(client: client,
logger: logger,
transaction: transaction,
package: package)
let result = try await database.transaction { tx in
// Wrap in a Result to avoid throwing out of the transaction, causing a roll-back
await Result {
try await updateRepository(on: tx, package: package)

try await applyVersionDelta(on: transaction, delta: versionDelta)
let versionDelta = try await diffVersions(client: client, logger: logger, transaction: tx,
package: package)

let newVersions = versionDelta.toAdd
try await applyVersionDelta(on: tx, delta: versionDelta)

mergeReleaseInfo(package: package, into: newVersions)
let newVersions = versionDelta.toAdd

let versionsPkgInfo = newVersions.compactMap { version -> (Version, PackageInfo)? in
guard let pkgInfo = try? getPackageInfo(package: package, version: version) else { return nil }
return (version, pkgInfo)
}
if !newVersions.isEmpty && versionsPkgInfo.isEmpty {
throw AppError.noValidVersions(package.model.id, package.model.url)
}
mergeReleaseInfo(package: package, into: newVersions)

for (version, pkgInfo) in versionsPkgInfo {
try await updateVersion(on: transaction,
version: version,
packageInfo: pkgInfo).get()
try await recreateProducts(on: transaction,
version: version,
manifest: pkgInfo.packageManifest)
try await recreateTargets(on: transaction,
version: version,
manifest: pkgInfo.packageManifest)
}
let versionsPkgInfo = newVersions.compactMap { version -> (Version, PackageInfo)? in
guard let pkgInfo = try? getPackageInfo(package: package, version: version) else { return nil }
return (version, pkgInfo)
}
if !newVersions.isEmpty && versionsPkgInfo.isEmpty {
throw AppError.noValidVersions(package.model.id, package.model.url)
}

for (version, pkgInfo) in versionsPkgInfo {
try await updateVersion(on: tx, version: version, packageInfo: pkgInfo).get()
try await recreateProducts(on: tx, version: version, manifest: pkgInfo.packageManifest)
try await recreateTargets(on: tx, version: version, manifest: pkgInfo.packageManifest)
}

let versions = try await updateLatestVersions(on: transaction, package: package)
let versions = try await updateLatestVersions(on: tx, package: package)

updateScore(package: package, versions: versions)
updateScore(package: package, versions: versions)

await onNewVersions(client: client,
logger: logger,
package: package,
versions: newVersions)
await onNewVersions(client: client, logger: logger, package: package, versions: newVersions)
}
}
try result.get()
}


Expand Down