mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-09-01 08:54:08 +00:00
fix performance issue
This commit is contained in:
parent
1891f1ee18
commit
644a2c1e3a
1 changed files with 19 additions and 4 deletions
|
|
@ -4,6 +4,7 @@ import 'dart:collection';
|
||||||
import 'package:blurhash_dart/blurhash_dart.dart' as bh;
|
import 'package:blurhash_dart/blurhash_dart.dart' as bh;
|
||||||
import 'package:clock/clock.dart';
|
import 'package:clock/clock.dart';
|
||||||
import 'package:drift/drift.dart' show Value;
|
import 'package:drift/drift.dart' show Value;
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:image/image.dart' as img;
|
import 'package:image/image.dart' as img;
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:twonly/locator.dart';
|
import 'package:twonly/locator.dart';
|
||||||
|
|
@ -259,7 +260,12 @@ class MemoriesService {
|
||||||
// Phase 2: Background — hash, crop analysis, size calculation.
|
// Phase 2: Background — hash, crop analysis, size calculation.
|
||||||
// Each DB write here fires the stream subscription above, keeping
|
// Each DB write here fires the stream subscription above, keeping
|
||||||
// the gallery state fresh without a separate notification step.
|
// the gallery state fresh without a separate notification step.
|
||||||
await _backgroundProcessPendingFiles(pendingFiles);
|
_dbSubscription?.pause();
|
||||||
|
try {
|
||||||
|
await _backgroundProcessPendingFiles(pendingFiles);
|
||||||
|
} finally {
|
||||||
|
_dbSubscription?.resume();
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Log.error('Error in background migration queue: $e');
|
Log.error('Error in background migration queue: $e');
|
||||||
}
|
}
|
||||||
|
|
@ -291,9 +297,8 @@ class MemoriesService {
|
||||||
: mediaService.originalPath;
|
: mediaService.originalPath;
|
||||||
if (imageFile.existsSync()) {
|
if (imageFile.existsSync()) {
|
||||||
final bytes = await imageFile.readAsBytes();
|
final bytes = await imageFile.readAsBytes();
|
||||||
final image = img.decodeImage(bytes);
|
final blurhash = await compute(_calculateBlurhash, bytes);
|
||||||
if (image != null) {
|
if (blurhash != null) {
|
||||||
final blurhash = bh.BlurHash.encode(image).hash;
|
|
||||||
await twonlyDB.mediaFilesDao.updateMedia(
|
await twonlyDB.mediaFilesDao.updateMedia(
|
||||||
mediaFile.mediaId,
|
mediaFile.mediaId,
|
||||||
MediaFilesCompanion(blurhash: Value(blurhash)),
|
MediaFilesCompanion(blurhash: Value(blurhash)),
|
||||||
|
|
@ -384,3 +389,13 @@ class MemoriesService {
|
||||||
_stateController.close();
|
_stateController.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String? _calculateBlurhash(Uint8List bytes) {
|
||||||
|
try {
|
||||||
|
final image = img.decodeImage(bytes);
|
||||||
|
if (image != null) {
|
||||||
|
return bh.BlurHash.encode(image).hash;
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue