kopia lustrzana https://gitlab.com/mysocialportal/relatica
Add clear cache functionality and defer connection details loading until needed
rodzic
1d63f7d0f0
commit
d9fc66ba2a
|
@ -5,6 +5,8 @@ import '../../models/exec_error.dart';
|
|||
import '../../models/group_data.dart';
|
||||
|
||||
abstract class IGroupsRepo {
|
||||
void clear();
|
||||
|
||||
void addAllGroups(List<GroupData> groups);
|
||||
|
||||
void addConnectionToGroup(GroupData group, Connection connection);
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import '../../models/hashtag.dart';
|
||||
|
||||
class IHashtagRepo {
|
||||
void add(Hashtag tag) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
abstract class IHashtagRepo {
|
||||
Future<void> clear();
|
||||
|
||||
List<String> getMatchingHashTags(String text) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
void add(Hashtag tag);
|
||||
|
||||
List<String> getMatchingHashTags(String text);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,13 @@ class MemoryGroupsRepo implements IGroupsRepo {
|
|||
final _connectionsForGroup = <String, Set<Connection>>{};
|
||||
final _myGroups = <GroupData>{};
|
||||
|
||||
@override
|
||||
void clear() {
|
||||
_groupsForConnection.clear();
|
||||
_connectionsForGroup.clear();
|
||||
_myGroups.clear();
|
||||
}
|
||||
|
||||
@override
|
||||
Result<List<GroupData>, ExecError> getGroupsForUser(String id) {
|
||||
if (!_groupsForConnection.containsKey(id)) {
|
||||
|
|
|
@ -11,6 +11,11 @@ class ObjectBoxHashtagRepo implements IHashtagRepo {
|
|||
box = getIt<ObjectBoxCache>().store.box<Hashtag>();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clear() async {
|
||||
await box.removeAllAsync();
|
||||
}
|
||||
|
||||
@override
|
||||
void add(Hashtag tag) {
|
||||
box.putAsync(tag);
|
||||
|
|
|
@ -127,3 +127,49 @@ Future<void> updateProfileDependencyInjectors(Profile profile) async {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
void clearCaches() {
|
||||
getIt<ActiveProfileSelector<IConnectionsRepo>>().activeEntry.match(
|
||||
onSuccess: (repo) => repo.clear(),
|
||||
onError: (error) =>
|
||||
_logger.severe('Error clearing IConnections Repo: $error'),
|
||||
);
|
||||
|
||||
getIt<ActiveProfileSelector<DirectMessageService>>().activeEntry.match(
|
||||
onSuccess: (service) => service.clear(),
|
||||
onError: (error) =>
|
||||
_logger.severe('Error clearing DirectMessageService Repo: $error'),
|
||||
);
|
||||
|
||||
getIt<ActiveProfileSelector<EntryManagerService>>().activeEntry.match(
|
||||
onSuccess: (service) => service.clear(),
|
||||
onError: (error) =>
|
||||
_logger.severe('Error clearing EntryManagerService Repo: $error'),
|
||||
);
|
||||
|
||||
getIt<ActiveProfileSelector<FollowRequestsManager>>().activeEntry.match(
|
||||
onSuccess: (manager) => manager.clear(),
|
||||
onError: (error) =>
|
||||
_logger.severe('Error clearing FollowRequestsManager Repo: $error'),
|
||||
);
|
||||
|
||||
getIt<ActiveProfileSelector<GalleryService>>().activeEntry.match(
|
||||
onSuccess: (service) => service.clear(),
|
||||
onError: (error) =>
|
||||
_logger.severe('Error clearing GalleryService Repo: $error'),
|
||||
);
|
||||
|
||||
getIt<HashtagService>().clear();
|
||||
|
||||
getIt<ActiveProfileSelector<NotificationsManager>>().activeEntry.match(
|
||||
onSuccess: (manager) => manager.clear(),
|
||||
onError: (error) =>
|
||||
_logger.severe('Error clearing NotificationsManager Repo: $error'),
|
||||
);
|
||||
|
||||
getIt<ActiveProfileSelector<TimelineManager>>().activeEntry.match(
|
||||
onSuccess: (manager) => manager.clear(),
|
||||
onError: (error) =>
|
||||
_logger.severe('Error clearing TimelineManager Repo: $error'),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -400,7 +400,7 @@ class NotificationsClient extends FriendicaClient {
|
|||
final url =
|
||||
'https://$serverName/api/v1/notifications/${notification.id}/dismiss';
|
||||
final request = Uri.parse(url);
|
||||
_logger.finest(() => 'Clearing unread notification for $notification');
|
||||
_logger.fine(() => 'Clearing unread notification for $notification');
|
||||
final response = await postUrl(request, {}, headers: _headers);
|
||||
return response.mapValue((value) => true);
|
||||
}
|
||||
|
@ -413,7 +413,7 @@ class RelationshipsClient extends FriendicaClient {
|
|||
|
||||
FutureResult<PagedResponse<List<Connection>>, ExecError> getMyFollowing(
|
||||
PagingData page) async {
|
||||
_logger.finest(() => 'Getting following with paging data $page');
|
||||
_logger.fine(() => 'Getting following with paging data $page');
|
||||
_networkStatusService.startConnectionUpdateStatus();
|
||||
final myId = profile.userId;
|
||||
final baseUrl = 'https://$serverName/api/v1/accounts/$myId';
|
||||
|
|
|
@ -88,9 +88,3 @@ Future<String?> showChooseOptions(
|
|||
},
|
||||
);
|
||||
}
|
||||
|
||||
// void clearCaches() {
|
||||
// getIt<TimelineManager>().clear();
|
||||
// getIt<IConnectionsRepo>().clear();
|
||||
// getIt<NotificationsManager>().clear();
|
||||
// }
|
||||
|
|
|
@ -47,7 +47,7 @@ class _FollowRequestAdjudicationScreenState
|
|||
.getByUserId(widget.userId)
|
||||
.mapValue((request) => request.connection);
|
||||
} else {
|
||||
result = cm.getById(widget.userId);
|
||||
result = cm.getById(widget.userId, forceUpdate: true);
|
||||
}
|
||||
|
||||
late final Widget body;
|
||||
|
@ -56,7 +56,7 @@ class _FollowRequestAdjudicationScreenState
|
|||
} else {
|
||||
final contact = result.value;
|
||||
final contactStatus = cm
|
||||
.getById(widget.userId)
|
||||
.getById(widget.userId, forceUpdate: true)
|
||||
.getValueOrElse(() => Connection(status: ConnectionStatus.none))
|
||||
.status;
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ import 'package:provider/provider.dart';
|
|||
|
||||
import '../controls/responsive_max_width.dart';
|
||||
import '../controls/standard_appbar.dart';
|
||||
import '../di_initialization.dart';
|
||||
import '../globals.dart';
|
||||
import '../services/setting_service.dart';
|
||||
import '../utils/theme_mode_extensions.dart';
|
||||
|
||||
|
@ -23,6 +25,7 @@ class SettingsScreen extends StatelessWidget {
|
|||
buildLowBandwidthWidget(settings),
|
||||
buildThemeWidget(settings),
|
||||
if (!kReleaseMode) buildColorBlindnessTestSettings(settings),
|
||||
buildClearCaches(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -72,4 +75,23 @@ class SettingsScreen extends StatelessWidget {
|
|||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildClearCaches(BuildContext context) {
|
||||
return ListTile(
|
||||
title: const Text('Clear local caches'),
|
||||
subtitle: const Text('This does not affect server side data at all.'),
|
||||
trailing: ElevatedButton(
|
||||
onPressed: () async {
|
||||
final confirm = await showYesNoDialog(context,
|
||||
'Are you sure you want to clear all local data for this account?');
|
||||
if (confirm != true) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearCaches();
|
||||
},
|
||||
child: const Text('Clear'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,14 @@ class UserProfileScreen extends StatefulWidget {
|
|||
class _UserProfileScreenState extends State<UserProfileScreen> {
|
||||
var isUpdating = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
getIt<ActiveProfileSelector<ConnectionsManager>>().activeEntry.withResult(
|
||||
(m) => m.getById(widget.userId, forceUpdate: true),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final manager = context
|
||||
|
|
|
@ -23,6 +23,13 @@ class ConnectionsManager extends ChangeNotifier {
|
|||
|
||||
ConnectionsManager(this.conRepo, this.groupsRepo);
|
||||
|
||||
void clear() {
|
||||
conRepo.clear();
|
||||
groupsRepo.clear();
|
||||
groupsNotInitialized = true;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
List<Connection> getKnownUsersByName(String name) {
|
||||
return conRepo.getKnownUsersByName(name);
|
||||
}
|
||||
|
@ -200,13 +207,12 @@ class ConnectionsManager extends ChangeNotifier {
|
|||
}
|
||||
|
||||
List<GroupData> getMyGroups() {
|
||||
final myGroups = groupsRepo.getMyGroups();
|
||||
if (groupsNotInitialized) {
|
||||
groupsNotInitialized = true;
|
||||
groupsNotInitialized = false;
|
||||
_updateMyGroups(true);
|
||||
}
|
||||
|
||||
return myGroups;
|
||||
return groupsRepo.getMyGroups();
|
||||
}
|
||||
|
||||
Result<List<Connection>, ExecError> getGroupMembers(GroupData group) {
|
||||
|
@ -325,9 +331,9 @@ class ConnectionsManager extends ChangeNotifier {
|
|||
);
|
||||
}
|
||||
|
||||
Result<Connection, ExecError> getById(String id) {
|
||||
Result<Connection, ExecError> getById(String id, {bool forceUpdate = false}) {
|
||||
return conRepo.getById(id).andThenSuccess((c) {
|
||||
if (c.status == ConnectionStatus.unknown) {
|
||||
if (forceUpdate) {
|
||||
_refreshConnection(c, true);
|
||||
}
|
||||
return c;
|
||||
|
|
|
@ -18,6 +18,12 @@ class DirectMessageService extends ChangeNotifier {
|
|||
final _threads = <String, DirectMessageThread>{};
|
||||
var _firstLoading = true;
|
||||
|
||||
void clear() {
|
||||
_threads.clear();
|
||||
_firstLoading = true;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
List<DirectMessageThread> getThreads({bool unreadyOnly = false}) {
|
||||
if (_threads.isEmpty && _firstLoading) {
|
||||
updateThreads();
|
||||
|
|
|
@ -17,6 +17,10 @@ class FollowRequestsManager extends ChangeNotifier {
|
|||
|
||||
List<FollowRequest> get requests => UnmodifiableListView(_requests.values);
|
||||
|
||||
void clear() {
|
||||
_requests.clear();
|
||||
}
|
||||
|
||||
Result<FollowRequest, ExecError> getByUserId(String id) {
|
||||
final request = _requests[id];
|
||||
return request != null
|
||||
|
|
|
@ -18,6 +18,14 @@ class GalleryService extends ChangeNotifier {
|
|||
|
||||
bool get loaded => _loaded;
|
||||
|
||||
void clear() {
|
||||
_galleries.clear();
|
||||
_galleryPages.clear();
|
||||
_images.clear();
|
||||
_loaded = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
List<GalleryData> getGalleries() {
|
||||
if (_galleries.isEmpty) {
|
||||
updateGalleries();
|
||||
|
|
|
@ -11,6 +11,11 @@ class HashtagService extends ChangeNotifier {
|
|||
repo = getIt<IHashtagRepo>();
|
||||
}
|
||||
|
||||
Future<void> clear() async {
|
||||
await repo.clear();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void add(Hashtag tag) {
|
||||
repo.add(tag);
|
||||
notifyListeners();
|
||||
|
|
|
@ -13,6 +13,12 @@ class InteractionsManager extends ChangeNotifier {
|
|||
final _likesByStatusId = <String, List<Connection>>{};
|
||||
final _resharesByStatusId = <String, List<Connection>>{};
|
||||
|
||||
void clear() {
|
||||
_likesByStatusId.clear();
|
||||
_resharesByStatusId.clear();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
List<Connection> getLikes(String statusId) {
|
||||
if (!_likesByStatusId.containsKey(statusId)) {
|
||||
updateLikesForStatus(statusId);
|
||||
|
|
|
@ -65,6 +65,8 @@ class NotificationsManager extends ChangeNotifier {
|
|||
void clear() {
|
||||
_notifications.clear();
|
||||
_pm.clear();
|
||||
_firstLoad = true;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
FutureResult<List<UserNotification>, ExecError> updateNotifications() async {
|
||||
|
|
|
@ -35,9 +35,10 @@ class TimelineManager extends ChangeNotifier {
|
|||
TimelineManager(this.groupsRepo, this.entryManagerService);
|
||||
|
||||
void clear() {
|
||||
groupsNotInitialized = true;
|
||||
cachedTimelines.clear();
|
||||
entryManagerService.clear();
|
||||
groupsRepo.clearMyGroups();
|
||||
groupsRepo.clear();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue