diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f335a92ff..1f61a82744 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ Version 71 ---------- *in development* +* 🔨 Cloud: do not fail when uploading more than 500 new shows. + #### 71.0.0 🧪 *2023-11-17* diff --git a/app/src/main/java/com/battlelancer/seriesguide/sync/HexagonEpisodeSync.java b/app/src/main/java/com/battlelancer/seriesguide/sync/HexagonEpisodeSync.java index 4e6b1925f3..61f988db7f 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/sync/HexagonEpisodeSync.java +++ b/app/src/main/java/com/battlelancer/seriesguide/sync/HexagonEpisodeSync.java @@ -33,6 +33,7 @@ public class HexagonEpisodeSync { + // See API documentation on list size limit. public static final int MAX_BATCH_SIZE = 500; private final Context context; diff --git a/app/src/main/java/com/battlelancer/seriesguide/sync/HexagonMovieSync.kt b/app/src/main/java/com/battlelancer/seriesguide/sync/HexagonMovieSync.kt index 7663e159f4..84435d03fa 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/sync/HexagonMovieSync.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/sync/HexagonMovieSync.kt @@ -11,9 +11,9 @@ import android.text.TextUtils import androidx.preference.PreferenceManager import com.battlelancer.seriesguide.backend.HexagonTools import com.battlelancer.seriesguide.backend.settings.HexagonSettings +import com.battlelancer.seriesguide.movies.tools.MovieTools import com.battlelancer.seriesguide.provider.SeriesGuideContract import com.battlelancer.seriesguide.provider.SgRoomDatabase -import com.battlelancer.seriesguide.movies.tools.MovieTools import com.battlelancer.seriesguide.util.DBUtils import com.battlelancer.seriesguide.util.Errors import com.google.api.client.util.DateTime @@ -22,7 +22,6 @@ import com.uwetrottmann.seriesguide.backend.movies.model.Movie import com.uwetrottmann.seriesguide.backend.movies.model.MovieList import timber.log.Timber import java.io.IOException -import java.util.ArrayList internal class HexagonMovieSync( private val context: Context, @@ -222,14 +221,10 @@ internal class HexagonMovieSync( return true } - // Upload in small batches - val wrapper = MovieList() - while (movies.isNotEmpty()) { - wrapper.movies = ArrayList() - while (movies.isNotEmpty() && wrapper.movies.size < MAX_BATCH_SIZE) { - wrapper.movies.add(movies.removeFirst()) - } - + // Upload in batches + movies.chunked(MAX_BATCH_SIZE).forEach { chunk -> + val wrapper = MovieList() + wrapper.movies = chunk try { // get service each time to check if auth was removed val moviesService = hexagonTools.moviesService ?: return false @@ -265,6 +260,7 @@ internal class HexagonMovieSync( } companion object { + // See API documentation on list size limit. private const val MAX_BATCH_SIZE = 500 } diff --git a/app/src/main/java/com/battlelancer/seriesguide/sync/HexagonShowSync.kt b/app/src/main/java/com/battlelancer/seriesguide/sync/HexagonShowSync.kt index 705daffaae..2bf0d8f9d3 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/sync/HexagonShowSync.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/sync/HexagonShowSync.kt @@ -409,19 +409,20 @@ class HexagonShowSync @Inject constructor( // https://github.com/UweTrottmann/SeriesGuide/issues/781 Timber.i("upload: %d shows", shows.size) - // wrap into helper object - val showList = SgCloudShowList() - showList.shows = shows - - // upload shows - try { - // get service each time to check if auth was removed - val showsService = hexagonTools.showsService ?: return false - showsService.saveSgShows(showList).execute() - } catch (e: IOException) { - logAndReportHexagon("save shows", e) - return false + // Upload in batches + shows.chunked(MAX_BATCH_SIZE).forEach { chunk -> + val wrapper = SgCloudShowList() + wrapper.shows = chunk + try { + // get service each time to check if auth was removed + val showsService = hexagonTools.showsService ?: return false + showsService.saveSgShows(wrapper).execute() + } catch (e: IOException) { + logAndReportHexagon("save shows", e) + return false + } } + return true } @@ -431,4 +432,9 @@ class HexagonShowSync @Inject constructor( } } + companion object { + // See API documentation on list size limit. + const val MAX_BATCH_SIZE = 500 + } + }