Skip to content

Commit

Permalink
Enable gzip compression for Sync PATCH payloads (#2805)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1206919211758354/f

Description:
This change adds gzip compression to all Sync data PATCH requests.
  • Loading branch information
ayoy authored May 10, 2024
1 parent 62145ff commit 27e7f4d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,13 @@ extension Pixel {
case syncSentUnauthenticatedRequest
case syncMetadataCouldNotLoadDatabase
case syncBookmarksFailed
case syncBookmarksPatchCompressionFailed
case syncCredentialsProviderInitializationFailed
case syncCredentialsFailed
case syncCredentialsPatchCompressionFailed
case syncSettingsFailed
case syncSettingsMetadataUpdateFailed
case syncSettingsPatchCompressionFailed
case syncSignupError
case syncLoginError
case syncLogoutError
Expand Down Expand Up @@ -1173,10 +1176,13 @@ extension Pixel.Event {
case .syncSentUnauthenticatedRequest: return "m_d_sync_sent_unauthenticated_request"
case .syncMetadataCouldNotLoadDatabase: return "m_d_sync_metadata_could_not_load_database"
case .syncBookmarksFailed: return "m_d_sync_bookmarks_failed"
case .syncBookmarksPatchCompressionFailed: return "m_d_sync_bookmarks_patch_compression_failed"
case .syncCredentialsProviderInitializationFailed: return "m_d_sync_credentials_provider_initialization_failed"
case .syncCredentialsFailed: return "m_d_sync_credentials_failed"
case .syncCredentialsPatchCompressionFailed: return "m_d_sync_credentials_patch_compression_failed"
case .syncSettingsFailed: return "m_d_sync_settings_failed"
case .syncSettingsMetadataUpdateFailed: return "m_d_sync_settings_metadata_update_failed"
case .syncSettingsPatchCompressionFailed: return "m_d_sync_settings_patch_compression_failed"
case .syncSignupError: return "m_d_sync_signup_error"
case .syncLoginError: return "m_d_sync_login_error"
case .syncLogoutError: return "m_d_sync_logout_error"
Expand Down
10 changes: 10 additions & 0 deletions Core/SyncErrorHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ extension SyncErrorHandler {

private func handleError(_ error: Error, modelType: ModelType) {
switch error {
case SyncError.patchPayloadCompressionFailed(let errorCode):
let pixel: Pixel.Event = {
switch modelType {
case .bookmarks:
return .syncBookmarksPatchCompressionFailed
case .credentials:
return .syncCredentialsPatchCompressionFailed
}
}()
Pixel.fire(pixel: pixel, withAdditionalParameters: ["error": "\(errorCode)"])
case let syncError as SyncError:
handleSyncError(syncError, modelType: modelType)
default:
Expand Down
2 changes: 2 additions & 0 deletions Core/SyncSettingsAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public final class SyncSettingsAdapter {
syncErrorCancellable = provider.syncErrorPublisher
.sink { error in
switch error {
case SyncError.patchPayloadCompressionFailed(let errorCode):
Pixel.fire(pixel: .syncSettingsPatchCompressionFailed, withAdditionalParameters: ["error": "\(errorCode)"])
case let syncError as SyncError:
Pixel.fire(pixel: .syncSettingsFailed, error: syncError)
case let settingsMetadataError as SettingsSyncMetadataSaveError:
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9806,7 +9806,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 144.0.5;
version = 144.0.6;
};
};
9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"revision" : "151737e0b690437a127cc6f1b9f443481cf2f645",
"version" : "144.0.5"
"revision" : "72be4e73360989af170399bc063fd5c628e1e84c",
"version" : "144.0.6"
}
},
{
Expand Down Expand Up @@ -72,6 +72,15 @@
"version" : "2.3.0"
}
},
{
"identity" : "gzipswift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/1024jp/GzipSwift.git",
"state" : {
"revision" : "731037f6cc2be2ec01562f6597c1d0aa3fe6fd05",
"version" : "6.0.1"
}
},
{
"identity" : "ios-js-support",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -129,7 +138,7 @@
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "46989693916f56d1186bd59ac15124caef896560",
"version" : "1.3.1"
Expand Down
2 changes: 0 additions & 2 deletions DuckDuckGo/SyncSettingsViewController+SyncDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ extension SyncSettingsViewController: SyncManagementViewModelDelegate {
}
let confirmAction = UIAlertAction(title: UserText.syncTurnOffConfirmAction, style: .destructive) { _ in
self.onConfirmSyncDisable?()
continuation.resume(returning: true)
}
alert.addAction(cancelAction)
alert.addAction(confirmAction)
Expand Down Expand Up @@ -329,7 +328,6 @@ extension SyncSettingsViewController: SyncManagementViewModelDelegate {
}
alert.addAction(title: UserText.syncDeleteAllConfirmAction, style: .destructive) {
self.onConfirmAndDeleteAllData?()
continuation.resume(returning: true)
}
self.present(alert, animated: true)
}
Expand Down

0 comments on commit 27e7f4d

Please sign in to comment.