From 65322257ece1221098404f6eb7499b47e68a73f8 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Wed, 10 Jul 2024 20:00:16 +0400 Subject: [PATCH] refactor: Only use ws updates if the API version supports it --- .../get_it/api_connection_repository.dart | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/logic/get_it/api_connection_repository.dart b/lib/logic/get_it/api_connection_repository.dart index 5b06c563..f67b54ea 100644 --- a/lib/logic/get_it/api_connection_repository.dart +++ b/lib/logic/get_it/api_connection_repository.dart @@ -275,11 +275,14 @@ class ApiConnectionRepository { connectionStatus = ConnectionStatus.connected; _connectionStatusStream.add(connectionStatus); - _serverJobsStreamSubscription = - api.getServerJobsStream().listen((final List jobs) { - _apiData.serverJobs.data = jobs; - _dataStream.add(_apiData); - }); + if (VersionConstraint.parse(wsJobsUpdatesSupportedVersion) + .allows(Version.parse(apiVersion))) { + _serverJobsStreamSubscription = + api.getServerJobsStream().listen((final List jobs) { + _apiData.serverJobs.data = jobs; + _dataStream.add(_apiData); + }); + } // Use timer to periodically check for new jobs _timer = Timer.periodic( @@ -295,9 +298,14 @@ class ApiConnectionRepository { await _serverJobsStreamSubscription?.cancel(); } + static const String wsJobsUpdatesSupportedVersion = '>=3.3.0'; + Future _refetchEverything(final Version version) async { - await _apiData.serverJobs - .refetchData(version, () => _dataStream.add(_apiData)); + if (_serverJobsStreamSubscription == null || + _apiData.serverJobs.data == null) { + await _apiData.serverJobs + .refetchData(version, () => _dataStream.add(_apiData)); + } await _apiData.backups .refetchData(version, () => _dataStream.add(_apiData)); await _apiData.backupConfig @@ -347,8 +355,7 @@ class ApiData { ), serverJobs = ApiDataElement>( fetchData: () async => api.getServerJobs(), - // TODO: Figure this out later, as ws keeps this updated - ttl: 10000, + ttl: 10, ), backupConfig = ApiDataElement( fetchData: () async => api.getBackupsConfiguration(),