Add user ability to purge memory and persistent caches

codemagic-setup
Hank Grabowski 2023-01-23 22:36:14 -05:00
rodzic 61d12542fb
commit bf13e0674b
5 zmienionych plików z 44 dodań i 9 usunięć

Wyświetl plik

@ -4,6 +4,10 @@ import '../../models/connection.dart';
import '../../models/exec_error.dart'; import '../../models/exec_error.dart';
class IConnectionsRepo { class IConnectionsRepo {
void clear() {
throw UnimplementedError();
}
bool addConnection(Connection connection) { bool addConnection(Connection connection) {
throw UnimplementedError(); throw UnimplementedError();
} }

Wyświetl plik

@ -9,6 +9,13 @@ class MemoryConnectionsRepo implements IConnectionsRepo {
final _connectionsByName = <String, Connection>{}; final _connectionsByName = <String, Connection>{};
final _myContacts = <Connection>[]; final _myContacts = <Connection>[];
@override
void clear() {
_connectionsById.clear();
_connectionsByName.clear();
_myContacts.clear();
}
@override @override
bool addAllConnections(Iterable<Connection> newConnections) { bool addAllConnections(Iterable<Connection> newConnections) {
bool result = true; bool result = true;

Wyświetl plik

@ -16,6 +16,12 @@ class ObjectBoxConnectionsRepo implements IConnectionsRepo {
box = getIt<ObjectBoxCache>().store.box<Connection>(); box = getIt<ObjectBoxCache>().store.box<Connection>();
} }
@override
void clear() {
memCache.clear();
box.removeAll();
}
@override @override
bool addAllConnections(Iterable<Connection> newConnections) { bool addAllConnections(Iterable<Connection> newConnections) {
memCache.addAllConnections(newConnections); memCache.addAllConnections(newConnections);
@ -40,9 +46,10 @@ class ObjectBoxConnectionsRepo implements IConnectionsRepo {
return _getConnection( return _getConnection(
Connection_.id.equals(id), Connection_.id.equals(id),
).mapError( ).mapError(
(error) => error.copy( (error) =>
message: "Can't find Connection for ID: $id", error.copy(
), message: "Can't find Connection for ID: $id",
),
); );
} }
@ -55,9 +62,10 @@ class ObjectBoxConnectionsRepo implements IConnectionsRepo {
return _getConnection( return _getConnection(
Connection_.name.equals(name), Connection_.name.equals(name),
).mapError( ).mapError(
(error) => error.copy( (error) =>
message: "Can't find Connection for ID: $name", error.copy(
), message: "Can't find Connection for ID: $name",
),
); );
} }
@ -65,9 +73,9 @@ class ObjectBoxConnectionsRepo implements IConnectionsRepo {
List<Connection> getKnownUsersByName(String name) { List<Connection> getKnownUsersByName(String name) {
return box return box
.query( .query(
Connection_.name.contains(name, caseSensitive: false) | Connection_.name.contains(name, caseSensitive: false) |
Connection_.handle.contains(name, caseSensitive: false), Connection_.handle.contains(name, caseSensitive: false),
) )
.build() .build()
.find(); .find();
} }

Wyświetl plik

@ -2,9 +2,12 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import '../controls/app_bottom_nav_bar.dart'; import '../controls/app_bottom_nav_bar.dart';
import '../data/interfaces/connections_repo_intf.dart';
import '../globals.dart'; import '../globals.dart';
import '../routes.dart'; import '../routes.dart';
import '../services/auth_service.dart'; import '../services/auth_service.dart';
import '../services/notifications_manager.dart';
import '../services/timeline_manager.dart';
class MenusScreen extends StatelessWidget { class MenusScreen extends StatelessWidget {
static const menuButtonWidth = 350.0; static const menuButtonWidth = 350.0;
@ -17,6 +20,15 @@ class MenusScreen extends StatelessWidget {
buildMenuButton('Profile', () => context.pushNamed(ScreenPaths.profile)), buildMenuButton('Profile', () => context.pushNamed(ScreenPaths.profile)),
buildMenuButton( buildMenuButton(
'Settings', () => context.pushNamed(ScreenPaths.settings)), 'Settings', () => context.pushNamed(ScreenPaths.settings)),
buildMenuButton('Clear Caches', () async {
final confirm = await showYesNoDialog(
context, 'You want to clear all memory and disk cache data?');
if (confirm == true) {
getIt<TimelineManager>().clear();
getIt<IConnectionsRepo>().clear();
getIt<NotificationsManager>().clear();
}
}),
buildMenuButton('Logout', () async { buildMenuButton('Logout', () async {
final confirm = await showYesNoDialog(context, 'Log out account?'); final confirm = await showYesNoDialog(context, 'Log out account?');
if (confirm == true) { if (confirm == true) {

Wyświetl plik

@ -28,6 +28,10 @@ class NotificationsManager extends ChangeNotifier {
return result; return result;
} }
void clear() {
_notifications.clear();
}
FutureResult<List<UserNotification>, ExecError> updateNotifications() async { FutureResult<List<UserNotification>, ExecError> updateNotifications() async {
final auth = getIt<AuthService>(); final auth = getIt<AuthService>();
final clientResult = auth.currentClient; final clientResult = auth.currentClient;