Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

perf: add debouncer to reduce reloading of other tabs

ashilkn87fa67390035
diff --git a/lib/ui/collections/device/device_folders_grid_view.dart b/lib/ui/collections/device/device_folders_grid_view.dart
index 671f876351..cbc9e3b2f7 100644
--- a/lib/ui/collections/device/device_folders_grid_view.dart
+++ b/lib/ui/collections/device/device_folders_grid_view.dart
@@ -12,6 +12,7 @@ import 'package:photos/models/device_collection.dart';
import "package:photos/ui/collections/device/device_folder_item.dart";
import 'package:photos/ui/common/loading_widget.dart';
import 'package:photos/ui/viewer/gallery/empty_state.dart';
+import "package:photos/utils/debouncer.dart";
class DeviceFoldersGridView extends StatefulWidget {
const DeviceFoldersGridView({
@@ -27,6 +28,10 @@ class _DeviceFoldersGridViewState extends State<DeviceFoldersGridView> {
StreamSubscription<LocalPhotosUpdatedEvent>? _localFilesSubscription;
String _loadReason = "init";
final _logger = Logger((_DeviceFoldersGridViewState).toString());
+ final _debouncer = Debouncer(
+ const Duration(seconds: 2),
+ executionInterval: const Duration(seconds: 5),
+ );
@override
void initState() {
@@ -39,8 +44,12 @@ class _DeviceFoldersGridViewState extends State<DeviceFoldersGridView> {
});
_localFilesSubscription =
Bus.instance.on<LocalPhotosUpdatedEvent>().listen((event) {
- _loadReason = event.reason;
- setState(() {});
+ _debouncer.run(() async {
+ if (mounted) {
+ _loadReason = event.reason;
+ setState(() {});
+ }
+ });
});
super.initState();
diff --git a/lib/ui/collections/device/device_folders_vertical_grid_view.dart b/lib/ui/collections/device/device_folders_vertical_grid_view.dart
index ad7706bd7d..3844d14fb5 100644
--- a/lib/ui/collections/device/device_folders_vertical_grid_view.dart
+++ b/lib/ui/collections/device/device_folders_vertical_grid_view.dart
@@ -13,6 +13,7 @@ import 'package:photos/models/device_collection.dart';
import "package:photos/ui/collections/device/device_folder_item.dart";
import 'package:photos/ui/common/loading_widget.dart';
import 'package:photos/ui/viewer/gallery/empty_state.dart';
+import "package:photos/utils/debouncer.dart";
class DeviceFolderVerticalGridView extends StatelessWidget {
final Widget? appTitle;
@@ -58,6 +59,10 @@ class _DeviceFolderVerticalGridViewBodyState
StreamSubscription<LocalPhotosUpdatedEvent>? _localFilesSubscription;
String _loadReason = "init";
final logger = Logger((_DeviceFolderVerticalGridViewBodyState).toString());
+ final _debouncer = Debouncer(
+ const Duration(milliseconds: 1500),
+ executionInterval: const Duration(seconds: 4),
+ );
/*
Aspect ratio 1:1 Max width 224 Fixed gap 8
Width changes dynamically with screen width such that we can fit 2 in one row.
@@ -78,8 +83,12 @@ class _DeviceFolderVerticalGridViewBodyState
});
_localFilesSubscription =
Bus.instance.on<LocalPhotosUpdatedEvent>().listen((event) {
- _loadReason = event.reason;
- setState(() {});
+ _debouncer.run(() async {
+ if (mounted) {
+ _loadReason = event.reason;
+ setState(() {});
+ }
+ });
});
super.initState();
}
diff --git a/lib/ui/tabs/shared_collections_tab.dart b/lib/ui/tabs/shared_collections_tab.dart
index 665bb8623b..5ec1829634 100644
--- a/lib/ui/tabs/shared_collections_tab.dart
+++ b/lib/ui/tabs/shared_collections_tab.dart
@@ -19,6 +19,7 @@ import "package:photos/ui/components/models/button_type.dart";
import 'package:photos/ui/tabs/section_title.dart';
import "package:photos/ui/tabs/shared/empty_state.dart";
import "package:photos/ui/tabs/shared/quick_link_album_item.dart";
+import "package:photos/utils/debouncer.dart";
import "package:photos/utils/navigation_util.dart";
import "package:photos/utils/share_util.dart";
@@ -36,18 +37,31 @@ class _SharedCollectionsTabState extends State<SharedCollectionsTab>
late StreamSubscription<CollectionUpdatedEvent>
_collectionUpdatesSubscription;
late StreamSubscription<UserLoggedOutEvent> _loggedOutEvent;
+ final _debouncer = Debouncer(
+ const Duration(seconds: 2),
+ executionInterval: const Duration(seconds: 5),
+ );
@override
void initState() {
super.initState();
_localFilesSubscription =
Bus.instance.on<LocalPhotosUpdatedEvent>().listen((event) {
- debugPrint("SetState Shared Collections on ${event.reason}");
- setState(() {});
+ _debouncer.run(() async {
+ if (mounted) {
+ debugPrint("SetState Shared Collections on ${event.reason}");
+ setState(() {});
+ }
+ });
});
_collectionUpdatesSubscription =
Bus.instance.on<CollectionUpdatedEvent>().listen((event) {
- setState(() {});
+ _debouncer.run(() async {
+ if (mounted) {
+ debugPrint("SetState Shared Collections on ${event.reason}");
+ setState(() {});
+ }
+ });
});
_loggedOutEvent = Bus.instance.on<UserLoggedOutEvent>().listen((event) {
setState(() {});
diff --git a/lib/ui/tabs/user_collections_tab.dart b/lib/ui/tabs/user_collections_tab.dart
index 7c49f976f3..22f6f486bd 100644
--- a/lib/ui/tabs/user_collections_tab.dart
+++ b/lib/ui/tabs/user_collections_tab.dart
@@ -24,6 +24,7 @@ import 'package:photos/ui/components/buttons/icon_button_widget.dart';
import "package:photos/ui/tabs/section_title.dart";
import "package:photos/ui/viewer/actions/delete_empty_albums.dart";
import "package:photos/ui/viewer/gallery/empty_state.dart";
+import "package:photos/utils/debouncer.dart";
import 'package:photos/utils/local_settings.dart';
import "package:photos/utils/navigation_util.dart";
@@ -44,19 +45,31 @@ class _UserCollectionsTabState extends State<UserCollectionsTab>
AlbumSortKey? sortKey;
String _loadReason = "init";
final _scrollController = ScrollController();
+ final _debouncer = Debouncer(
+ const Duration(seconds: 2),
+ executionInterval: const Duration(seconds: 5),
+ );
static const int _kOnEnteItemLimitCount = 10;
@override
void initState() {
_localFilesSubscription =
Bus.instance.on<LocalPhotosUpdatedEvent>().listen((event) {
- _loadReason = event.reason;
- setState(() {});
+ _debouncer.run(() async {
+ if (mounted) {
+ _loadReason = event.reason;
+ setState(() {});
+ }
+ });
});
_collectionUpdatesSubscription =
Bus.instance.on<CollectionUpdatedEvent>().listen((event) {
- _loadReason = event.reason;
- setState(() {});
+ _debouncer.run(() async {
+ if (mounted) {
+ _loadReason = event.reason;
+ setState(() {});
+ }
+ });
});
_loggedOutEvent = Bus.instance.on<UserLoggedOutEvent>().listen((event) {
_loadReason = event.reason;