speed up series update
This commit is contained in:
@@ -185,6 +185,39 @@ class BackendApi {
|
||||
return (map['id'] as num).toInt();
|
||||
}
|
||||
|
||||
Future<int> upsertEpisodesBulk(int seasonId, List<Map<String, dynamic>> episodes) async {
|
||||
final map = await _post({
|
||||
'action': 'upsert_episodes_bulk',
|
||||
'season_id': seasonId,
|
||||
'episodes': episodes,
|
||||
});
|
||||
return (map['count'] as num?)?.toInt() ?? 0;
|
||||
}
|
||||
|
||||
Future<Map<int, int>> upsertSeasonsBulk(int showId, List<Map<String, dynamic>> seasons) async {
|
||||
final map = await _post({
|
||||
'action': 'upsert_seasons_bulk',
|
||||
'show_id': showId,
|
||||
'seasons': seasons,
|
||||
});
|
||||
final m = <int,int>{};
|
||||
final any = map['map'];
|
||||
if (any is Map) {
|
||||
for (final e in any.entries) {
|
||||
final k = int.tryParse(e.key.toString());
|
||||
final v = (e.value as num?)?.toInt();
|
||||
if (k != null && v != null) m[k] = v;
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> getCapabilities() async {
|
||||
final map = await _post({'action': 'get_capabilities'});
|
||||
final caps = map['capabilities'];
|
||||
return caps is Map<String, dynamic> ? caps : (caps as Map).cast<String, dynamic>();
|
||||
}
|
||||
|
||||
Future<int?> getShowDbIdByTmdbId(int tmdbId) async {
|
||||
final map = await _post({'action': 'get_show_by_tmdb', 'tmdb_id': tmdbId});
|
||||
final v = map['id'];
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
typedef CancelCheck = bool Function();
|
||||
|
||||
Iterable<List<T>> _chunked<T>(List<T> list, int size) sync* {
|
||||
if (size <= 0) size = 1;
|
||||
for (var i = 0; i < list.length; i += size) {
|
||||
final end = i + size;
|
||||
yield list.sublist(i, end > list.length ? list.length : end);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> runChunked<T>(
|
||||
Iterable<T> items,
|
||||
int chunkSize,
|
||||
Future<void> Function(T item) task, {
|
||||
CancelCheck? isCancelled,
|
||||
}) async {
|
||||
final list = items.toList();
|
||||
for (final chunk in _chunked(list, chunkSize)) {
|
||||
if (isCancelled?.call() == true) break;
|
||||
await Future.wait(
|
||||
chunk.map((e) async {
|
||||
if (isCancelled?.call() == true) return;
|
||||
await task(e);
|
||||
}),
|
||||
eagerError: false,
|
||||
);
|
||||
if (isCancelled?.call() == true) break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,15 @@ class AppConfig {
|
||||
|
||||
///defaultValue: 'eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJhMzMyNzFiOWU1NGNkY2I5YTgwNjgwZWFmNTUyMmYxYiIsIm5iZiI6MTM0ODc2NTY2MS4wLCJzdWIiOiI1MDY0ODdkZDE5YzI5NTY2M2MwMDBhOGIiLCJzY29wZXMiOlsiYXBpX3JlYWQiXSwidmVyc2lvbiI6MX0.m26QybYBGQVY8OuL87FFae3ThPqAnOqEwgbLMtnH0wo'
|
||||
);
|
||||
|
||||
// Concurrency caps
|
||||
static const tmdbSeasonFetchConcurrency = int.fromEnvironment(
|
||||
'TMDB_SEASON_CONCURRENCY',
|
||||
defaultValue: 3,
|
||||
);
|
||||
|
||||
static const dbEpisodeUpsertConcurrency = int.fromEnvironment(
|
||||
'DB_EPISODE_UPSERT_CONCURRENCY',
|
||||
defaultValue: 12,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user