mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-03 08:40:44 +02:00
perf(downloads): stream concurrent native queue work
This commit is contained in:
@@ -60,6 +60,7 @@ class DownloadRequestPayload {
|
||||
final String qualityVariant;
|
||||
final bool qualityVariantCollisionOnly;
|
||||
final String songLinkRegion;
|
||||
final int networkConcurrencyLimit;
|
||||
|
||||
const DownloadRequestPayload({
|
||||
this.contractVersion = nativeWorkerContractVersion,
|
||||
@@ -121,6 +122,7 @@ class DownloadRequestPayload {
|
||||
this.qualityVariant = '',
|
||||
this.qualityVariantCollisionOnly = false,
|
||||
this.songLinkRegion = 'US',
|
||||
this.networkConcurrencyLimit = 3,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
@@ -184,6 +186,7 @@ class DownloadRequestPayload {
|
||||
'quality_variant': qualityVariant,
|
||||
'quality_variant_collision_only': qualityVariantCollisionOnly,
|
||||
'songlink_region': songLinkRegion,
|
||||
'network_concurrency_limit': networkConcurrencyLimit,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -251,6 +254,7 @@ class DownloadRequestPayload {
|
||||
qualityVariant: qualityVariant,
|
||||
qualityVariantCollisionOnly: qualityVariantCollisionOnly,
|
||||
songLinkRegion: songLinkRegion,
|
||||
networkConcurrencyLimit: networkConcurrencyLimit,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1192,6 +1192,34 @@ class PlatformBridge {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> appendNativeDownloadWorkerRequests({
|
||||
required String runId,
|
||||
required List<Map<String, dynamic>> requests,
|
||||
}) async {
|
||||
if (requests.isEmpty) return;
|
||||
final payloadDir = await _nativeWorkerPayloadDir();
|
||||
final stamp = DateTime.now().microsecondsSinceEpoch;
|
||||
final requestPath = '${payloadDir.path}/append_$stamp.json';
|
||||
await File(requestPath).writeAsString(jsonEncode(requests), flush: true);
|
||||
try {
|
||||
await _channel.invokeMethod('appendNativeDownloadWorkerRequests', {
|
||||
'run_id': runId,
|
||||
'requests_path': requestPath,
|
||||
});
|
||||
} catch (_) {
|
||||
unawaited(_deleteFileIfExists(requestPath));
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> finishNativeDownloadWorkerPreparation({
|
||||
required String runId,
|
||||
}) async {
|
||||
await _channel.invokeMethod('finishNativeDownloadWorkerPreparation', {
|
||||
'run_id': runId,
|
||||
});
|
||||
}
|
||||
|
||||
static Future<void> _deleteFileIfExists(String path) async {
|
||||
try {
|
||||
final file = File(path);
|
||||
|
||||
Reference in New Issue
Block a user