mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-30 13:19:44 +02:00
perf(downloads): reuse HTTP connections between tracks
This commit is contained in:
1 parent
1a4b90db43
commit
dab5f770ab
2 files changed
+7
-14
No files matched your search
@@ -320,7 +320,6 @@ class DownloadQueueNotifier extends Notifier<DownloadQueueState> {
|
||||
final QueueProcessingGate _queueProcessingGate = QueueProcessingGate();
|
||||
StreamSubscription<List<ConnectivityResult>>? _connectivitySub;
|
||||
int _downloadCount = 0;
|
||||
static const _cleanupInterval = 50;
|
||||
static const _progressPollingInterval = Duration(milliseconds: 1200);
|
||||
static const _idleProgressPollEveryTicks = 3;
|
||||
static const _progressStreamBootstrapTimeout = Duration(seconds: 3);
|
||||
@@ -1897,17 +1896,18 @@ class DownloadQueueNotifier extends Notifier<DownloadQueueState> {
|
||||
await PlatformBridge.endBackgroundDownloadTask();
|
||||
}
|
||||
|
||||
if (_downloadCount > 0) {
|
||||
_log.d('Final connection cleanup...');
|
||||
if (stoppedWhilePaused && _downloadCount > 0) {
|
||||
try {
|
||||
await PlatformBridge.cleanupConnections();
|
||||
} catch (e) {
|
||||
_log.e('Final cleanup failed: $e');
|
||||
}
|
||||
_downloadCount = 0;
|
||||
}
|
||||
_downloadCount = 0;
|
||||
|
||||
if (!stoppedWhilePaused) {
|
||||
// Releasing idle runtimes already recycles the Rust HTTP pool. A
|
||||
// separate cleanup immediately beforehand only builds it twice.
|
||||
await PlatformBridge.releaseNativeMemory();
|
||||
}
|
||||
|
||||
|
||||
@@ -251,16 +251,9 @@ class _DownloadRun {
|
||||
}
|
||||
|
||||
n._downloadCount++;
|
||||
if (n._downloadCount % DownloadQueueNotifier._cleanupInterval == 0) {
|
||||
_log.d(
|
||||
'Cleaning up idle connections (after ${n._downloadCount} downloads)...',
|
||||
);
|
||||
try {
|
||||
await PlatformBridge.cleanupConnections();
|
||||
} catch (e) {
|
||||
_log.e('Connection cleanup failed: $e');
|
||||
}
|
||||
}
|
||||
// The HTTP pool expires idle connections itself. Keep warm connections
|
||||
// for the next track; network changes/errors and queue teardown still
|
||||
// recycle the pool when needed.
|
||||
} catch (e, stackTrace) {
|
||||
await _handleRunException(e, stackTrace);
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user