Skip to content

Commit 9fb1467

Browse files
Merge pull request #4032 from SwiftPackageIndex/mitigate-gitlab-500s-part-6
Mitigate gitlab 500s part 6
2 parents 7b11d78 + 51579d8 commit 9fb1467

4 files changed

Lines changed: 26 additions & 5 deletions

File tree

Sources/App/Core/Constants.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@ enum Constants {
4949

5050
// package
5151
static let maxKeywordPackageCollectionCount = 300
52+
53+
// HTTP client
54+
// 2026-04-14 sas: For details, see: https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/4024#issuecomment-4237684071
55+
static let httpDecompressionSizeLimit = 1_000_000
5256
}

Sources/App/Core/Dependencies/BuildSystemClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ extension BuildSystemClient: DependencyKey {
3535
getStatusCount: { status in
3636
try await Gitlab.Builder.getStatusCount(status: status,
3737
page: 1,
38-
pageSize: 20,
39-
maxPageCount: 10)
38+
pageSize: 100,
39+
maxPageCount: 5)
4040
},
4141
triggerBuild: { buildId, cloneURL, isDocBuild, platform, ref, swiftVersion, versionID in
4242
try await Gitlab.Builder.triggerBuild(buildId: buildId,

Sources/App/Core/Dependencies/HTTPClient.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extension HTTPClient: DependencyKey {
3737
.init(
3838
get: { url, headers in
3939
let req = try Request(url: url, method: .GET, headers: headers)
40-
return try await Vapor.HTTPClient.shared.execute(request: req).get()
40+
return try await shared.execute(request: req).get()
4141
},
4242
post: { url, headers, body in
4343
let req = try Request(url: url, method: .POST, headers: headers, body: body.map({.data($0)}))
@@ -71,6 +71,8 @@ extension HTTPClient: DependencyKey {
7171
func post(url: String, body: Data?) async throws -> Response {
7272
try await post(url: url, headers: .init(), body: body)
7373
}
74+
75+
private static var shared: Vapor.HTTPClient { globallySharedHTTPClient }
7476
}
7577

7678

@@ -87,6 +89,21 @@ extension DependencyValues {
8789
}
8890

8991

92+
private let globallySharedHTTPClient: Vapor.HTTPClient = {
93+
var conf = Vapor.HTTPClient.Configuration.singletonConfiguration
94+
// 2026-04-14 sas: Increasing limit from default `.enabled(limit: .ratio(25))`, which caused requests to fail in the past.
95+
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/4024#issuecomment-4237684071
96+
conf.decompression = .enabled(limit: .size(Constants.httpDecompressionSizeLimit))
97+
98+
let httpClient = Vapor.HTTPClient(
99+
eventLoopGroup: Vapor.HTTPClient.defaultEventLoopGroup,
100+
configuration: conf,
101+
backgroundActivityLogger: .noop
102+
)
103+
return httpClient
104+
}()
105+
106+
90107
#if DEBUG
91108
// Convenience initialisers to make testing easier
92109

Sources/App/Core/Dependencies/LoggerClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ extension DependencyValues {
4040
}
4141

4242

43-
#if DEBUG
4443
extension Logger {
4544
static var noop: Self { .init(label: "noop") { _ in SwiftLogNoOpLogHandler() } }
4645

46+
#if DEBUG
4747
static func testLogger(_ handler: LogHandler) -> Self {
4848
.init(label: "test", factory: { _ in handler })
4949
}
50-
}
5150
#endif
51+
}

0 commit comments

Comments
 (0)