Revert "Cache LinagoraEcosystem to avoid multiple network calls"
This reverts commit 252f34f914fa21f8acf2ef2b5de9ac0ab28a8b4c.
This commit is contained in:
@@ -48,7 +48,6 @@ import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_sto
|
|||||||
import 'package:tmail_ui_user/features/push_notification/presentation/bindings/fcm_interactor_bindings.dart';
|
import 'package:tmail_ui_user/features/push_notification/presentation/bindings/fcm_interactor_bindings.dart';
|
||||||
import 'package:tmail_ui_user/features/push_notification/presentation/bindings/web_socket_interactor_bindings.dart';
|
import 'package:tmail_ui_user/features/push_notification/presentation/bindings/web_socket_interactor_bindings.dart';
|
||||||
import 'package:tmail_ui_user/features/push_notification/presentation/config/fcm_configuration.dart';
|
import 'package:tmail_ui_user/features/push_notification/presentation/config/fcm_configuration.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/cache/linagora_ecosystem_cache.dart';
|
|
||||||
import 'package:tmail_ui_user/features/push_notification/presentation/controller/fcm_message_controller.dart';
|
import 'package:tmail_ui_user/features/push_notification/presentation/controller/fcm_message_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/push_notification/presentation/controller/fcm_token_controller.dart';
|
import 'package:tmail_ui_user/features/push_notification/presentation/controller/fcm_token_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/push_notification/presentation/controller/web_socket_controller.dart';
|
import 'package:tmail_ui_user/features/push_notification/presentation/controller/web_socket_controller.dart';
|
||||||
@@ -597,7 +596,6 @@ abstract class BaseController extends GetxController
|
|||||||
authorizationInterceptors.clear();
|
authorizationInterceptors.clear();
|
||||||
authorizationIsolateInterceptors.clear();
|
authorizationIsolateInterceptors.clear();
|
||||||
await cachingManager.closeHive();
|
await cachingManager.closeHive();
|
||||||
LinagoraEcosystemCache().clearCache();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logWarning('BaseController::clearAllData: Cannot clear all data: $e');
|
logWarning('BaseController::clearAllData: Cannot clear all data: $e');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/linagora_ecosystem.dart';
|
|
||||||
|
|
||||||
class LinagoraEcosystemCache {
|
|
||||||
static final LinagoraEcosystemCache _instance = LinagoraEcosystemCache._internal();
|
|
||||||
|
|
||||||
factory LinagoraEcosystemCache() => _instance;
|
|
||||||
|
|
||||||
LinagoraEcosystemCache._internal();
|
|
||||||
|
|
||||||
final Map<String, LinagoraEcosystem> _cache = {};
|
|
||||||
|
|
||||||
void cacheEcosystem(LinagoraEcosystem ecosystem, String baseUrl) {
|
|
||||||
_cache[baseUrl] = ecosystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
LinagoraEcosystem? getCachedEcosystem(String baseUrl) {
|
|
||||||
return _cache[baseUrl];
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearCache() {
|
|
||||||
_cache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasCachedEcosystem(String baseUrl) {
|
|
||||||
return _cache.containsKey(baseUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@ import 'package:core/data/network/dio_client.dart';
|
|||||||
import 'package:core/utils/app_logger.dart';
|
import 'package:core/utils/app_logger.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/extensions/service_path_extension.dart';
|
import 'package:tmail_ui_user/features/login/data/extensions/service_path_extension.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/network/endpoint.dart';
|
import 'package:tmail_ui_user/features/login/data/network/endpoint.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/cache/linagora_ecosystem_cache.dart';
|
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/exceptions/linagora_ecosystem_exceptions.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/exceptions/linagora_ecosystem_exceptions.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/api_url_linagora_ecosystem.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/api_url_linagora_ecosystem.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/linagora_ecosystem.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/linagora_ecosystem.dart';
|
||||||
@@ -18,51 +17,45 @@ class LinagoraEcosystemApi {
|
|||||||
LinagoraEcosystemApi(this._dioClient);
|
LinagoraEcosystemApi(this._dioClient);
|
||||||
|
|
||||||
Future<LinagoraEcosystem> getLinagoraEcosystem(String baseUrl) async {
|
Future<LinagoraEcosystem> getLinagoraEcosystem(String baseUrl) async {
|
||||||
final cachedEcosystem = LinagoraEcosystemCache().getCachedEcosystem(baseUrl);
|
|
||||||
if (cachedEcosystem != null) {
|
|
||||||
log('LinagoraEcosystemApi::getLinagoraEcosystem: Using cached data');
|
|
||||||
return cachedEcosystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
final result = await _dioClient.get(
|
final result = await _dioClient.get(
|
||||||
Endpoint.linagoraEcosystem.usingBaseUrl(baseUrl).generateEndpointPath(),
|
Endpoint.linagoraEcosystem.usingBaseUrl(baseUrl).generateEndpointPath(),
|
||||||
);
|
);
|
||||||
log('LinagoraEcosystemApi::getLinagoraEcosystem: $result');
|
log('LinagoraEcosystemApi::getLinagoraEcosystem: $result');
|
||||||
|
|
||||||
LinagoraEcosystem ecosystem;
|
|
||||||
if (result is Map<String, dynamic>) {
|
if (result is Map<String, dynamic>) {
|
||||||
ecosystem = LinagoraEcosystem.deserialize(result);
|
return LinagoraEcosystem.deserialize(result);
|
||||||
} else if (result is String) {
|
} else if (result is String) {
|
||||||
ecosystem = LinagoraEcosystem.deserialize(jsonDecode(result));
|
return LinagoraEcosystem.deserialize(jsonDecode(result));
|
||||||
} else {
|
} else {
|
||||||
throw NotFoundLinagoraEcosystem();
|
throw NotFoundLinagoraEcosystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
LinagoraEcosystemCache().cacheEcosystem(ecosystem, baseUrl);
|
|
||||||
|
|
||||||
return ecosystem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<PaywallUrlPattern> getPaywallUrl(String baseUrl) async {
|
Future<PaywallUrlPattern> getPaywallUrl(String baseUrl) async {
|
||||||
|
final result = await _dioClient.get(
|
||||||
|
Endpoint.linagoraEcosystem.usingBaseUrl(baseUrl).generateEndpointPath(),
|
||||||
|
);
|
||||||
|
log('LinagoraEcosystemApi::getPaywallUrl: $result');
|
||||||
|
|
||||||
LinagoraEcosystem? linagoraEcosystem;
|
LinagoraEcosystem? linagoraEcosystem;
|
||||||
|
|
||||||
try {
|
if (result is Map<String, dynamic>) {
|
||||||
linagoraEcosystem = await getLinagoraEcosystem(baseUrl);
|
linagoraEcosystem = LinagoraEcosystem.deserialize(result);
|
||||||
} catch (exception) {
|
} else if (result is String) {
|
||||||
if (exception is NotFoundLinagoraEcosystem) {
|
linagoraEcosystem = LinagoraEcosystem.deserialize(jsonDecode(result));
|
||||||
throw NotFoundPaywallUrl();
|
|
||||||
}
|
|
||||||
rethrow;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final paywallProperty =
|
if (linagoraEcosystem == null) {
|
||||||
linagoraEcosystem.properties?[LinagoraEcosystemIdentifier.paywallURL] as ApiUrlLinagoraEcosystem?;
|
throw NotFoundLinagoraEcosystem();
|
||||||
log('LinagoraEcosystemApi::getPaywallUrl: paywallProperty = $paywallProperty');
|
|
||||||
|
|
||||||
if (paywallProperty == null) {
|
|
||||||
throw NotFoundPaywallUrl();
|
|
||||||
} else {
|
} else {
|
||||||
return PaywallUrlPattern(paywallProperty.value);
|
final paywallProperty =
|
||||||
|
linagoraEcosystem.properties?[LinagoraEcosystemIdentifier.paywallURL] as ApiUrlLinagoraEcosystem?;
|
||||||
|
log('LinagoraEcosystemApi::getPaywallUrl: paywallProperty = $paywallProperty');
|
||||||
|
|
||||||
|
if (paywallProperty == null) {
|
||||||
|
throw NotFoundPaywallUrl();
|
||||||
|
} else {
|
||||||
|
return PaywallUrlPattern(paywallProperty.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,106 +0,0 @@
|
|||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/data/cache/linagora_ecosystem_cache.dart';
|
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/linagora_ecosystem.dart';
|
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/linagora_ecosystem_identifier.dart';
|
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/linagora_ecosystem_properties.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
group('LinagoraEcosystemCache Test', () {
|
|
||||||
const testBaseUrl = 'https://example.com';
|
|
||||||
const differentBaseUrl = 'https://different.com';
|
|
||||||
|
|
||||||
final testEcosystem = LinagoraEcosystem({
|
|
||||||
LinagoraEcosystemIdentifier.linShareApiUrl: ApiUrlLinagoraEcosystem('https://linshare.com/api'),
|
|
||||||
});
|
|
||||||
|
|
||||||
final differentEcosystem = LinagoraEcosystem({
|
|
||||||
LinagoraEcosystemIdentifier.twakeApiUrl: ApiUrlLinagoraEcosystem('https://twake.com/api'),
|
|
||||||
});
|
|
||||||
|
|
||||||
tearDown(() {
|
|
||||||
// Clear cache after each test
|
|
||||||
LinagoraEcosystemCache().clearCache();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should cache and retrieve ecosystem correctly', () {
|
|
||||||
// Cache the ecosystem
|
|
||||||
LinagoraEcosystemCache().cacheEcosystem(testEcosystem, testBaseUrl);
|
|
||||||
|
|
||||||
// Retrieve from cache
|
|
||||||
final cachedEcosystem = LinagoraEcosystemCache().getCachedEcosystem(testBaseUrl);
|
|
||||||
|
|
||||||
expect(cachedEcosystem, isNotNull);
|
|
||||||
expect(cachedEcosystem, equals(testEcosystem));
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should return null for different base URL', () {
|
|
||||||
// Cache the ecosystem for one base URL
|
|
||||||
LinagoraEcosystemCache().cacheEcosystem(testEcosystem, testBaseUrl);
|
|
||||||
|
|
||||||
// Try to retrieve for different base URL
|
|
||||||
final cachedEcosystem = LinagoraEcosystemCache().getCachedEcosystem(differentBaseUrl);
|
|
||||||
|
|
||||||
expect(cachedEcosystem, isNull);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should return null when cache is empty', () {
|
|
||||||
final cachedEcosystem = LinagoraEcosystemCache().getCachedEcosystem(testBaseUrl);
|
|
||||||
|
|
||||||
expect(cachedEcosystem, isNull);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should clear cache correctly', () {
|
|
||||||
// Cache the ecosystem
|
|
||||||
LinagoraEcosystemCache().cacheEcosystem(testEcosystem, testBaseUrl);
|
|
||||||
|
|
||||||
// Verify it's cached
|
|
||||||
var cachedEcosystem = LinagoraEcosystemCache().getCachedEcosystem(testBaseUrl);
|
|
||||||
expect(cachedEcosystem, isNotNull);
|
|
||||||
|
|
||||||
// Clear cache
|
|
||||||
LinagoraEcosystemCache().clearCache();
|
|
||||||
|
|
||||||
// Verify it's cleared
|
|
||||||
cachedEcosystem = LinagoraEcosystemCache().getCachedEcosystem(testBaseUrl);
|
|
||||||
expect(cachedEcosystem, isNull);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should handle multiple base URLs correctly', () {
|
|
||||||
// Cache ecosystems for different base URLs
|
|
||||||
LinagoraEcosystemCache().cacheEcosystem(testEcosystem, testBaseUrl);
|
|
||||||
LinagoraEcosystemCache().cacheEcosystem(differentEcosystem, differentBaseUrl);
|
|
||||||
|
|
||||||
// Verify each base URL gets its own ecosystem
|
|
||||||
final cachedTestEcosystem = LinagoraEcosystemCache().getCachedEcosystem(testBaseUrl);
|
|
||||||
final cachedDifferentEcosystem = LinagoraEcosystemCache().getCachedEcosystem(differentBaseUrl);
|
|
||||||
|
|
||||||
expect(cachedTestEcosystem, equals(testEcosystem));
|
|
||||||
expect(cachedDifferentEcosystem, equals(differentEcosystem));
|
|
||||||
});
|
|
||||||
|
|
||||||
test('hasCachedEcosystem should return correct boolean', () {
|
|
||||||
// Initially should be false
|
|
||||||
expect(LinagoraEcosystemCache().hasCachedEcosystem(testBaseUrl), isFalse);
|
|
||||||
|
|
||||||
// After caching should be true
|
|
||||||
LinagoraEcosystemCache().cacheEcosystem(testEcosystem, testBaseUrl);
|
|
||||||
expect(LinagoraEcosystemCache().hasCachedEcosystem(testBaseUrl), isTrue);
|
|
||||||
|
|
||||||
// After clearing should be false again
|
|
||||||
LinagoraEcosystemCache().clearCache();
|
|
||||||
expect(LinagoraEcosystemCache().hasCachedEcosystem(testBaseUrl), isFalse);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
class ApiUrlLinagoraEcosystem extends LinagoraEcosystemProperties {
|
|
||||||
final String value;
|
|
||||||
|
|
||||||
ApiUrlLinagoraEcosystem(this.value);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [value];
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool? get stringify => true;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user