mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
feat(mobile): Various minor performance improvements (#1176)
* Improve scroll performance by introducing repaint boundaries and moving more calculations to providers. * Add error handing for malformed dates. * Remove unused method * Use compute in different places to improve app performance during heavy tasks * Fix test * Refactor `List<RenderAssetGridElement>` to separate `RenderList` class and make `fromAssetGroups` a static method of this class. * Fix loading indicator bug * Use provider directly * `RenderList` refactoring * `AssetNotifier` refactoring * Move `combine` to static private method * Extract compute methods in cache services to static private methods. * Use `tryParse` instead of `parse` with try/catch for dates. * Fix bug in caching mechanism. * Fixed state not being used to trigger conditional rendering * styling * Corrected state Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
92972ac776
commit
7a1ae8691e
15 changed files with 312 additions and 242 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
abstract class JsonCache<T> {
|
||||
|
|
@ -31,8 +32,13 @@ abstract class JsonCache<T> {
|
|||
}
|
||||
}
|
||||
|
||||
static Future<String> _computeEncodeJson(dynamic toEncode) async {
|
||||
return json.encode(toEncode);
|
||||
}
|
||||
|
||||
Future<void> putRawData(dynamic data) async {
|
||||
final jsonString = json.encode(data);
|
||||
final jsonString = await compute(_computeEncodeJson, data);
|
||||
|
||||
final file = await _getCacheFile();
|
||||
|
||||
if (!await file.exists()) {
|
||||
|
|
@ -42,10 +48,15 @@ abstract class JsonCache<T> {
|
|||
await file.writeAsString(jsonString);
|
||||
}
|
||||
|
||||
dynamic readRawData() async {
|
||||
static Future<dynamic> _computeDecodeJson(String jsonString) async {
|
||||
return json.decode(jsonString);
|
||||
}
|
||||
|
||||
Future<dynamic> readRawData() async {
|
||||
final file = await _getCacheFile();
|
||||
final data = await file.readAsString();
|
||||
return json.decode(data);
|
||||
|
||||
return await compute(_computeDecodeJson, data);
|
||||
}
|
||||
|
||||
void put(T data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue