Skip to content

Commit

Permalink
Merge branch 'hexagon-fixes' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Dec 7, 2023
2 parents 319be5b + 8a2d041 commit 17b7847
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/assemble-test-lint.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -265,6 +260,7 @@ internal class HexagonMovieSync(
}

companion object {
// See API documentation on list size limit.
private const val MAX_BATCH_SIZE = 500
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -431,4 +432,9 @@ class HexagonShowSync @Inject constructor(
}
}

companion object {
// See API documentation on list size limit.
const val MAX_BATCH_SIZE = 500
}

}

0 comments on commit 17b7847

Please sign in to comment.