Sfoglia il codice sorgente

Improve logging for gallery logs

Neeraj Gupta 2 anni fa
parent
commit
2fa1c19d0c

+ 15 - 7
lib/ui/huge_listview/lazy_loading_gallery.dart

@@ -27,6 +27,7 @@ class LazyLoadingGallery extends StatefulWidget {
   final GalleryLoader asyncLoader;
   final GalleryLoader asyncLoader;
   final SelectedFiles selectedFiles;
   final SelectedFiles selectedFiles;
   final String tag;
   final String tag;
+  final String logTag;
   final Stream<int> currentIndexStream;
   final Stream<int> currentIndexStream;
   final bool smallerTodayFont;
   final bool smallerTodayFont;
 
 
@@ -40,6 +41,7 @@ class LazyLoadingGallery extends StatefulWidget {
     this.tag,
     this.tag,
     this.currentIndexStream, {
     this.currentIndexStream, {
     this.smallerTodayFont,
     this.smallerTodayFont,
+    this.logTag = "",
     Key key,
     Key key,
   }) : super(key: key ?? UniqueKey());
   }) : super(key: key ?? UniqueKey());
 
 
@@ -52,7 +54,7 @@ class _LazyLoadingGalleryState extends State<LazyLoadingGallery> {
   static const kRecycleLimit = 400;
   static const kRecycleLimit = 400;
   static const kNumberOfDaysToRenderBeforeAndAfter = 8;
   static const kNumberOfDaysToRenderBeforeAndAfter = 8;
 
 
-  static final Logger _logger = Logger("LazyLoadingGallery");
+  Logger _logger;
 
 
   List<File> _files;
   List<File> _files;
   StreamSubscription<FilesUpdatedEvent> _reloadEventSubscription;
   StreamSubscription<FilesUpdatedEvent> _reloadEventSubscription;
@@ -66,9 +68,9 @@ class _LazyLoadingGalleryState extends State<LazyLoadingGallery> {
   }
   }
 
 
   void _init() {
   void _init() {
+    _logger = Logger("LazyLoading_${widget.logTag}");
     _shouldRender = true;
     _shouldRender = true;
     _files = widget.files;
     _files = widget.files;
-
     _reloadEventSubscription = widget.reloadEvent.listen((e) => _onReload(e));
     _reloadEventSubscription = widget.reloadEvent.listen((e) => _onReload(e));
 
 
     _currentIndexSubscription =
     _currentIndexSubscription =
@@ -93,11 +95,13 @@ class _LazyLoadingGalleryState extends State<LazyLoadingGallery> {
           fileDate.day == galleryDate.day;
           fileDate.day == galleryDate.day;
     });
     });
     if (filesUpdatedThisDay.isNotEmpty) {
     if (filesUpdatedThisDay.isNotEmpty) {
-      _logger.info(
-        filesUpdatedThisDay.length.toString() +
-            " files were updated on " +
-            getDayTitle(galleryDate.microsecondsSinceEpoch),
-      );
+      if (kDebugMode) {
+        _logger.info(
+          filesUpdatedThisDay.length.toString() +
+              " files were updated due to ${event.type} on " +
+              getDayTitle(galleryDate.microsecondsSinceEpoch),
+        );
+      }
       if (event.type == EventType.addedOrUpdated) {
       if (event.type == EventType.addedOrUpdated) {
         final dayStartTime =
         final dayStartTime =
             DateTime(galleryDate.year, galleryDate.month, galleryDate.day);
             DateTime(galleryDate.year, galleryDate.month, galleryDate.day);
@@ -124,6 +128,10 @@ class _LazyLoadingGalleryState extends State<LazyLoadingGallery> {
             _files = files;
             _files = files;
           });
           });
         }
         }
+      } else {
+        if (kDebugMode) {
+          debugPrint("Unexpected event ${event.type.name}");
+        }
       }
       }
     }
     }
   }
   }

+ 2 - 1
lib/ui/shared_collections_gallery.dart

@@ -45,11 +45,12 @@ class _SharedCollectionGalleryState extends State<SharedCollectionGallery>
   void initState() {
   void initState() {
     _localFilesSubscription =
     _localFilesSubscription =
         Bus.instance.on<LocalPhotosUpdatedEvent>().listen((event) {
         Bus.instance.on<LocalPhotosUpdatedEvent>().listen((event) {
-      _logger.info("Files updated");
+      debugPrint("SetState Shared Collections on LocalPhotosUpdatedEvent");
       setState(() {});
       setState(() {});
     });
     });
     _collectionUpdatesSubscription =
     _collectionUpdatesSubscription =
         Bus.instance.on<CollectionUpdatedEvent>().listen((event) {
         Bus.instance.on<CollectionUpdatedEvent>().listen((event) {
+      debugPrint("SetState Shared Collections on CollectionUpdatedEvent");
       setState(() {});
       setState(() {});
     });
     });
     _loggedOutEvent = Bus.instance.on<UserLoggedOutEvent>().listen((event) {
     _loggedOutEvent = Bus.instance.on<UserLoggedOutEvent>().listen((event) {

+ 13 - 9
lib/ui/viewer/gallery/gallery.dart

@@ -2,6 +2,7 @@
 
 
 import 'dart:async';
 import 'dart:async';
 
 
+import 'package:flutter/foundation.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
 import 'package:logging/logging.dart';
 import 'package:logging/logging.dart';
 import 'package:photos/core/constants.dart';
 import 'package:photos/core/constants.dart';
@@ -77,16 +78,18 @@ class _GalleryState extends State<Gallery> {
   StreamSubscription<FilesUpdatedEvent> _reloadEventSubscription;
   StreamSubscription<FilesUpdatedEvent> _reloadEventSubscription;
   StreamSubscription<TabDoubleTapEvent> _tabDoubleTapEvent;
   StreamSubscription<TabDoubleTapEvent> _tabDoubleTapEvent;
   final _forceReloadEventSubscriptions = <StreamSubscription<Event>>[];
   final _forceReloadEventSubscriptions = <StreamSubscription<Event>>[];
+  String _logTag;
 
 
   @override
   @override
   void initState() {
   void initState() {
-    _logger = Logger("Gallery_" + widget.tagPrefix);
+    _logTag =
+        "Gallery_${widget.tagPrefix}${kDebugMode ? "_" + widget.albumName : ""}";
+    _logger = Logger(_logTag);
+    _logger.finest("init Gallery");
     _itemScroller = ItemScrollController();
     _itemScroller = ItemScrollController();
-
-    _logger.info("initState");
     if (widget.reloadEvent != null) {
     if (widget.reloadEvent != null) {
       _reloadEventSubscription = widget.reloadEvent.listen((event) async {
       _reloadEventSubscription = widget.reloadEvent.listen((event) async {
-        _logger.info("Building gallery because reload event fired");
+        _logger.info("Reloading ALL files on ${event.type.name} event");
         final result = await _loadFiles();
         final result = await _loadFiles();
         _onFilesLoaded(result.files);
         _onFilesLoaded(result.files);
       });
       });
@@ -160,18 +163,18 @@ class _GalleryState extends State<Gallery> {
 
 
   // Collates files and returns `true` if it resulted in a gallery reload
   // Collates files and returns `true` if it resulted in a gallery reload
   bool _onFilesLoaded(List<File> files) {
   bool _onFilesLoaded(List<File> files) {
-    final collatedFiles = _collateFiles(files);
-    if (_collatedFiles.length != collatedFiles.length ||
+    final updatedCollatedFiles = _collateFiles(files);
+    if (_collatedFiles.length != updatedCollatedFiles.length ||
         _collatedFiles.isEmpty) {
         _collatedFiles.isEmpty) {
       if (mounted) {
       if (mounted) {
         setState(() {
         setState(() {
           _hasLoadedFiles = true;
           _hasLoadedFiles = true;
-          _collatedFiles = collatedFiles;
+          _collatedFiles = updatedCollatedFiles;
         });
         });
       }
       }
       return true;
       return true;
     } else {
     } else {
-      _collatedFiles = collatedFiles;
+      _collatedFiles = updatedCollatedFiles;
       return false;
       return false;
     }
     }
   }
   }
@@ -188,7 +191,7 @@ class _GalleryState extends State<Gallery> {
 
 
   @override
   @override
   Widget build(BuildContext context) {
   Widget build(BuildContext context) {
-    _logger.info("Building " + widget.tagPrefix);
+    _logger.finest("Building Gallery  ${widget.tagPrefix}");
     if (!_hasLoadedFiles) {
     if (!_hasLoadedFiles) {
       return const EnteLoadingWidget();
       return const EnteLoadingWidget();
     }
     }
@@ -238,6 +241,7 @@ class _GalleryState extends State<Gallery> {
               .where((event) => event.tag == widget.tagPrefix)
               .where((event) => event.tag == widget.tagPrefix)
               .map((event) => event.index),
               .map((event) => event.index),
           smallerTodayFont: widget.smallerTodayFont,
           smallerTodayFont: widget.smallerTodayFont,
+          logTag: _logTag,
         );
         );
         if (widget.header != null && index == 0) {
         if (widget.header != null && index == 0) {
           gallery = Column(children: [widget.header, gallery]);
           gallery = Column(children: [widget.header, gallery]);