use asynccache
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:async/async.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/album.interface.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/album_asset.interface.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/album_etag.interface.dart';
|
||||
@@ -14,10 +15,13 @@ import 'package:immich_mobile/utils/isolate_helper.dart';
|
||||
import 'package:immich_mobile/utils/mixins/log.mixin.dart';
|
||||
|
||||
class AlbumSyncService with LogMixin {
|
||||
const AlbumSyncService();
|
||||
AlbumSyncService();
|
||||
|
||||
final _fullDeviceSyncCache = AsyncCache<bool>.ephemeral();
|
||||
|
||||
Future<bool> performFullDeviceSyncIsolate() async {
|
||||
return await IsolateHelper.run(performFullDeviceSync);
|
||||
return await _fullDeviceSyncCache
|
||||
.fetch(() async => await IsolateHelper.run(performFullDeviceSync));
|
||||
}
|
||||
|
||||
Future<bool> performFullDeviceSync() async {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:async/async.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/api/sync_api.interface.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/asset.interface.dart';
|
||||
@@ -13,20 +14,24 @@ import 'package:immich_mobile/utils/isolate_helper.dart';
|
||||
import 'package:immich_mobile/utils/mixins/log.mixin.dart';
|
||||
|
||||
class AssetSyncService with LogMixin {
|
||||
const AssetSyncService();
|
||||
AssetSyncService();
|
||||
|
||||
final _fullRemoteSyncCache = AsyncCache<bool>.ephemeral();
|
||||
|
||||
Future<bool> performFullRemoteSyncIsolate(
|
||||
User user, {
|
||||
DateTime? updatedUtil,
|
||||
int? limit,
|
||||
}) async {
|
||||
return await IsolateHelper.run(() async {
|
||||
return await performFullRemoteSync(
|
||||
user,
|
||||
updatedUtil: updatedUtil,
|
||||
limit: limit,
|
||||
);
|
||||
});
|
||||
return await _fullRemoteSyncCache.fetch(
|
||||
() async => await IsolateHelper.run(() async {
|
||||
return await performFullRemoteSync(
|
||||
user,
|
||||
updatedUtil: updatedUtil,
|
||||
limit: limit,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> performFullRemoteSync(
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_web_auth_2/flutter_web_auth_2.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:immich_mobile/domain/interfaces/album.interface.dart';
|
||||
@@ -22,6 +20,7 @@ import 'package:immich_mobile/presentation/states/gallery_permission.state.dart'
|
||||
import 'package:immich_mobile/presentation/states/server_info.state.dart';
|
||||
import 'package:immich_mobile/service_locator.dart';
|
||||
import 'package:immich_mobile/utils/immich_api_client.dart';
|
||||
import 'package:immich_mobile/utils/isolate_helper.dart';
|
||||
import 'package:immich_mobile/utils/mixins/log.mixin.dart';
|
||||
|
||||
// Cannot add dependency repos to constructor as this requires the newly registered API client from login
|
||||
@@ -59,7 +58,7 @@ class LoginService with LogMixin {
|
||||
);
|
||||
|
||||
if (res.statusCode == HttpStatus.ok) {
|
||||
final data = await compute(jsonDecode, res.body);
|
||||
final data = await IsolateHelper.decodeJson(res.bodyBytes);
|
||||
final endpoint = data['api']['endpoint'].toString();
|
||||
|
||||
// Full URL is relative to base
|
||||
|
||||
Reference in New Issue
Block a user