mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-09 17:39:42 +00:00
refactor: Code deduplication in server data reload
This commit is contained in:
parent
caa2fd3b8e
commit
43a339af91
|
@ -250,17 +250,7 @@ class ApiConnectionRepository {
|
||||||
_dataStream.add(_apiData);
|
_dataStream.add(_apiData);
|
||||||
}
|
}
|
||||||
|
|
||||||
_apiData.serverJobs.data = await _apiData.serverJobs.fetchData();
|
await _refetchEverything(Version.parse(apiVersion));
|
||||||
_apiData.backupConfig.data = await _apiData.backupConfig.fetchData();
|
|
||||||
_apiData.backups.data = await _apiData.backups.fetchData();
|
|
||||||
_apiData.services.data = await _apiData.services.fetchData();
|
|
||||||
_apiData.volumes.data = await _apiData.volumes.fetchData();
|
|
||||||
_apiData.recoveryKeyStatus.data =
|
|
||||||
await _apiData.recoveryKeyStatus.fetchData();
|
|
||||||
_apiData.devices.data = await _apiData.devices.fetchData();
|
|
||||||
_apiData.users.data = await _apiData.users.fetchData();
|
|
||||||
_apiData.settings.data = await _apiData.settings.fetchData();
|
|
||||||
_dataStream.add(_apiData);
|
|
||||||
|
|
||||||
connectionStatus = ConnectionStatus.connected;
|
connectionStatus = ConnectionStatus.connected;
|
||||||
_connectionStatusStream.add(connectionStatus);
|
_connectionStatusStream.add(connectionStatus);
|
||||||
|
@ -272,6 +262,27 @@ class ApiConnectionRepository {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _refetchEverything(final Version version) async {
|
||||||
|
await _apiData.serverJobs
|
||||||
|
.refetchData(version, () => _dataStream.add(_apiData));
|
||||||
|
await _apiData.backups
|
||||||
|
.refetchData(version, () => _dataStream.add(_apiData));
|
||||||
|
await _apiData.backupConfig
|
||||||
|
.refetchData(version, () => _dataStream.add(_apiData));
|
||||||
|
await _apiData.services
|
||||||
|
.refetchData(version, () => _dataStream.add(_apiData));
|
||||||
|
await _apiData.volumes
|
||||||
|
.refetchData(version, () => _dataStream.add(_apiData));
|
||||||
|
await _apiData.recoveryKeyStatus
|
||||||
|
.refetchData(version, () => _dataStream.add(_apiData));
|
||||||
|
await _apiData.devices
|
||||||
|
.refetchData(version, () => _dataStream.add(_apiData));
|
||||||
|
await _apiData.users.refetchData(version, () => _dataStream.add(_apiData));
|
||||||
|
await _apiData.settings
|
||||||
|
.refetchData(version, () => _dataStream.add(_apiData));
|
||||||
|
print(_apiData.services.data?.length);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> reload(final Timer? timer) async {
|
Future<void> reload(final Timer? timer) async {
|
||||||
final serverDetails = getIt<ApiConfigModel>().serverDetails;
|
final serverDetails = getIt<ApiConfigModel>().serverDetails;
|
||||||
if (serverDetails == null) {
|
if (serverDetails == null) {
|
||||||
|
@ -289,23 +300,7 @@ class ApiConnectionRepository {
|
||||||
_apiData.apiVersion.data = apiVersion;
|
_apiData.apiVersion.data = apiVersion;
|
||||||
}
|
}
|
||||||
final Version version = Version.parse(apiVersion);
|
final Version version = Version.parse(apiVersion);
|
||||||
await _apiData.serverJobs
|
await _refetchEverything(version);
|
||||||
.refetchData(version, () => _dataStream.add(_apiData));
|
|
||||||
await _apiData.backups
|
|
||||||
.refetchData(version, () => _dataStream.add(_apiData));
|
|
||||||
await _apiData.backupConfig
|
|
||||||
.refetchData(version, () => _dataStream.add(_apiData));
|
|
||||||
await _apiData.services
|
|
||||||
.refetchData(version, () => _dataStream.add(_apiData));
|
|
||||||
await _apiData.volumes
|
|
||||||
.refetchData(version, () => _dataStream.add(_apiData));
|
|
||||||
await _apiData.recoveryKeyStatus
|
|
||||||
.refetchData(version, () => _dataStream.add(_apiData));
|
|
||||||
await _apiData.devices
|
|
||||||
.refetchData(version, () => _dataStream.add(_apiData));
|
|
||||||
await _apiData.users.refetchData(version, () => _dataStream.add(_apiData));
|
|
||||||
await _apiData.settings
|
|
||||||
.refetchData(version, () => _dataStream.add(_apiData));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void emitData() {
|
void emitData() {
|
||||||
|
@ -392,8 +387,11 @@ class ApiDataElement<T> {
|
||||||
final Version version,
|
final Version version,
|
||||||
final Function callback,
|
final Function callback,
|
||||||
) async {
|
) async {
|
||||||
|
print('Refetching data');
|
||||||
if (VersionConstraint.parse(requiredApiVersion).allows(version)) {
|
if (VersionConstraint.parse(requiredApiVersion).allows(version)) {
|
||||||
if (isExpired) {
|
print('Version is allowed');
|
||||||
|
if (isExpired || _data == null) {
|
||||||
|
print('Data is expired');
|
||||||
final newData = await fetchData();
|
final newData = await fetchData();
|
||||||
if (T is List) {
|
if (T is List) {
|
||||||
if (Object.hashAll(newData as Iterable<Object?>) !=
|
if (Object.hashAll(newData as Iterable<Object?>) !=
|
||||||
|
|
Loading…
Reference in a new issue