From 5b2bbb11236a6167f4089b4c4f8e643b7cedee28 Mon Sep 17 00:00:00 2001 From: KaiserBh Date: Wed, 10 Jan 2024 09:50:06 +1100 Subject: [PATCH] refactor(GoogleDrive): Use gson to encode the syncData. Same as before. OOM (Out of Memory) issue. Signed-off-by: KaiserBh --- .../data/sync/service/GoogleDriveSyncService.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt index ab3cdb81b..07e3cbfec 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt @@ -106,14 +106,12 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync override suspend fun pullSyncData(): SyncData? { val drive = googleDriveService.driveService - // Check if the Google Drive service is initialized if (drive == null) { logcat(LogPriority.ERROR) { "Google Drive service not initialized" } - throw Exception(context.getString(R.string.google_drive_not_signed_in)) + throw Exception(context.stringResource(MR.strings.google_drive_not_signed_in)) } - val fileList = getFileList(drive) - + val fileList = getAppDataFileList(drive) if (fileList.isEmpty()) { return null } @@ -121,12 +119,12 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync val outputStream = ByteArrayOutputStream() drive.files().get(gdriveFileId).executeMediaAndDownloadTo(outputStream) - val jsonString = withContext(Dispatchers.IO) { - val gzipInputStream = GZIPInputStream(ByteArrayInputStream(outputStream.toByteArray())) - gzipInputStream.bufferedReader(Charsets.UTF_8).use { it.readText() } - } - return json.decodeFromString(SyncData.serializer(), jsonString) + return withContext(Dispatchers.IO) { + val gzipInputStream = GZIPInputStream(ByteArrayInputStream(outputStream.toByteArray())) + val gson = Gson() + gson.fromJson(gzipInputStream.reader(Charsets.UTF_8), SyncData::class.java) + } } override suspend fun pushSyncData(syncData: SyncData) {