Skip to content
Merged
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
4 changes: 4 additions & 0 deletions app/lib/services/wals/sdcard_wal_sync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ class SDCardWalSyncImpl implements SDCardWalSync {
var timerStart = DateTime.now().millisecondsSinceEpoch ~/ 1000 - seconds;

var connection = await ServiceManager.instance().device.ensureConnection(deviceId);
if (connection == null) {
Logger.debug("SDCard: Failed to establish connection for device info");
return wals;
}
Comment on lines +178 to +181
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This null check correctly fixes the crash. However, looking at the context, the ensureConnection call on line 177 is the third such call in this method (the other two are inside _getStorageList on line 158 and _getAudioCodec on line 172). Each of these awaited calls can be a slow, battery-intensive operation.

To improve performance and reduce battery consumption, consider refactoring _getMissingWals to call ensureConnection only once at the beginning and pass the resulting connection object to the helper methods and for getting the device info.

References
  1. Prefer using existing helper functions over inlining their logic, especially when they handle complex cases like fallbacks or error handling. Inlining can introduce subtle bugs by missing parts of the original logic.

var pd = await _device!.getDeviceInfo(connection);
String deviceModel = pd.modelNumber.isNotEmpty ? pd.modelNumber : "Omi";

Expand Down