Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

🚑 hotfix for slow read notifications API #530

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/models/notifications/notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class OBNotification extends UpdatableModel<OBNotification> {
contentObjectData: json['content_object'], type: type);
}

if (json.containsKey('read')) {
if (json.containsKey('read') && !read) {
read = json['read'];
}

Expand Down
15 changes: 13 additions & 2 deletions lib/pages/home/pages/notifications/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,22 @@ class OBNotificationsPageState extends State<OBNotificationsPage>
}

Future<List<OBNotification>> _refreshGeneralNotifications() async {
// TODO[Performance] remove on the _refreshNotifications call is faster
_generalNotificationsListController.items().forEach((OBNotification notification) {
notification.markNotificationAsRead();
});
List<OBNotification> newNotifications =
await _refreshNotifications(_generalTypes);
await _refreshUnreadGeneralNotificationsCount();
return newNotifications;
}

Future<List<OBNotification>> _refreshRequestNotifications() async {
// TODO[Performance] remove onthe the _refreshNotifications call is faster
_requestsNotificationsListController.items().forEach((OBNotification notification) {
notification.markNotificationAsRead();
});

List<OBNotification> newNotifications =
await _refreshNotifications(_requestTypes);
await _refreshUnreadRequestNotificationsCount();
Expand All @@ -294,7 +303,9 @@ class OBNotificationsPageState extends State<OBNotificationsPage>

Future<List<OBNotification>> _refreshNotifications(
[List<NotificationType> types]) async {
await _readNotifications(types: types);
// TODO[Performance] This API call takes ages so we're not awaiting anymore.
// When the perf is improved, make sure to await before requesting new notifications
_readNotifications(types: types);

NotificationsList notificationsList =
await _userService.getNotifications(types: types);
Expand Down Expand Up @@ -332,7 +343,7 @@ class OBNotificationsPageState extends State<OBNotificationsPage>
}

int maxId = firstItem.id;
await _userService.readNotifications(maxId: maxId, types: types);
return _userService.readNotifications(maxId: maxId, types: types);
}

Future<List<OBNotification>> _loadMoreGeneralNotifications(
Expand Down
4 changes: 4 additions & 0 deletions lib/widgets/http_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,10 @@ class OBHttpListController<T> {
return _state._list.isNotEmpty;
}

List<T> items() {
return _state._list;
}

T firstItem() {
return _state._list.first;
}
Expand Down