diff --git a/.github/workflows/assemble-test-lint.yml b/.github/workflows/assemble-test-lint.yml index 6deb3d4ef2..3a4dca0bc6 100644 --- a/.github/workflows/assemble-test-lint.yml +++ b/.github/workflows/assemble-test-lint.yml @@ -1,11 +1,14 @@ name: Android CI +# Avoid running this on the gh-pages branch on: push: - branches: [ main, dev ] + branches-ignore: + - "gh-pages" pull_request: - branches: [ main, dev ] - workflow_dispatch: + branches-ignore: + - "gh-pages" + workflow_dispatch: # Allow running manually from web UI jobs: build: 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/backend/CloudEndpointUtils.kt b/app/src/main/java/com/battlelancer/seriesguide/backend/CloudEndpointUtils.kt index 9447e840c4..6a470d32ab 100644 --- a/app/src/main/java/com/battlelancer/seriesguide/backend/CloudEndpointUtils.kt +++ b/app/src/main/java/com/battlelancer/seriesguide/backend/CloudEndpointUtils.kt @@ -25,10 +25,10 @@ object CloudEndpointUtils { /** * Change this to 'true' if you're running your backend locally using the DevAppServer. */ - @Suppress("SimplifyBooleanWithConstants") + @Suppress("SimplifyBooleanWithConstants", "KotlinConstantConditions") private val USE_LOCAL_VERSION = false && BuildConfig.DEBUG - @Suppress("SimplifyBooleanWithConstants") + @Suppress("SimplifyBooleanWithConstants", "KotlinConstantConditions") private val USE_STAGING_VERSION = false && BuildConfig.DEBUG private const val ROOT_URL_STAGING = "https://staging-dot-optical-hexagon-364.appspot.com" 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 + } + }