Skip to content

Commit

Permalink
fix(data): fix date merge error
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuJHua committed Dec 15, 2024
1 parent b94b3f6 commit e95a820
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/pages/home/media/media_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MediaLogic extends GetxController with GetSingleTickerProviderStateMixin {
Future<void> cleanFile() async {
state.isCleaning = true;
update(['modal']);
await FileUtil.cleanFile();
await compute(FileUtil.cleanFile, FileUtil.getRealPath('database', ''));
await getFilePath(state.mediaType.value);
state.isCleaning = false;
update(['modal']);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/data/pref.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class PrefUtil {
/// 修复同步失败导致本地分类丢失
/// 视频缩略图重复生成
if (appVersion != null && appVersion.split('+')[0].compareTo('2.6.3') < 0) {
await FileUtil.cleanFile();
await compute(FileUtil.cleanFile, FileUtil.getRealPath('database', ''));
await MediaUtil.regenerateMissingThumbnails();
await compute(IsarUtil.fixV2_6_3, FileUtil.getRealPath('database', ''));
}
Expand Down
12 changes: 9 additions & 3 deletions lib/utils/file_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import 'dart:io';

import 'package:archive/archive_io.dart';
import 'package:get/get.dart';
import 'package:isar/isar.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';

import '../common/models/isar/category.dart';
import '../common/models/isar/diary.dart';
import '../common/values/media_type.dart';
import '../components/audio_player/audio_player_logic.dart';
Expand Down Expand Up @@ -213,7 +215,11 @@ class FileUtil {
await deleteMediaFiles(oldDiary.videoName, newDiary.videoName, 'thumbnail');
}

static Future<void> cleanFile() async {
static Future<void> cleanFile(String dir) async {
var isar = Isar.open(
schemas: [DiarySchema, CategorySchema],
directory: dir,
);
// 获取各类型的所有文件路径并转换为Set以提高查找效率
final imageFiles = (await FileUtil.getDirFileName(MediaType.image.value)).toSet();
final audioFiles = (await FileUtil.getDirFileName(MediaType.audio.value)).toSet();
Expand All @@ -225,12 +231,12 @@ class FileUtil {
final usedVideos = <String>{};

// 获取日记总数
final count = IsarUtil.countAllDiary();
final count = isar.diarys.count();

// 分批获取日记并收集引用的文件名
const batchSize = 50;
for (int i = 0; i < count; i += batchSize) {
final diaryList = await IsarUtil.getDiary(i, batchSize);
final diaryList = await isar.diarys.where().findAllAsync(offset: i, limit: batchSize);
for (var diary in diaryList) {
usedImages.addAll(diary.imageName);
usedAudios.addAll(diary.audioName);
Expand Down

0 comments on commit e95a820

Please sign in to comment.