🐛 Bug fixes of libraries

This commit is contained in:
2025-12-18 23:42:19 +08:00
parent 4f6e5883b7
commit a37d762b1b
4 changed files with 202 additions and 172 deletions

View File

@@ -24,13 +24,28 @@ class TrackRepository extends _$TrackRepository {
}
Future<void> importFiles(List<String> filePaths) async {
final db = ref.read(databaseProvider);
final settings = ref.read(settingsProvider).value;
final importMode = settings?.importMode ?? ImportMode.copy;
// Filter out files that are already indexed
final existingPaths = await (db.select(
db.tracks,
)..where((t) => t.path.isIn(filePaths))).map((t) => t.path).get();
final existingPathsSet = existingPaths.toSet();
final newFilePaths = filePaths
.where((path) => !existingPathsSet.contains(path))
.toList();
if (newFilePaths.isEmpty) {
return; // All files already indexed
}
if (importMode == ImportMode.copy) {
await _importFilesWithCopy(filePaths);
await _importFilesWithCopy(newFilePaths);
} else {
await _importFilesInPlace(filePaths);
await _importFilesInPlace(newFilePaths);
}
}