perf(library): batch album deletion and refresh once

This commit is contained in:
zarzet
2026-09-17 17:32:12 +07:00
parent c868aac2cc
commit 1ef81b4530
6 changed files with 224 additions and 14 deletions
+26
View File
@@ -3,6 +3,32 @@ import 'package:sqflite/sqflite.dart';
import 'package:spotiflac_android/utils/file_access.dart';
import 'package:spotiflac_android/utils/logger.dart';
/// Deletes a selection atomically without exceeding SQLite's parameter budget.
Future<void> deleteLibraryItemsByIds(Database db, Iterable<String> ids) async {
final uniqueIds = ids.toSet().toList();
if (uniqueIds.isEmpty) return;
await db.transaction((txn) async {
const chunkSize = 500;
for (var start = 0; start < uniqueIds.length; start += chunkSize) {
final chunk = uniqueIds.sublist(
start,
(start + chunkSize).clamp(0, uniqueIds.length),
);
final placeholders = List.filled(chunk.length, '?').join(',');
await txn.delete(
'library_path_keys',
where: 'item_id IN ($placeholders)',
whereArgs: chunk,
);
await txn.delete(
'library',
where: 'id IN ($placeholders)',
whereArgs: chunk,
);
}
});
}
Future<int> pruneUnreferencedLibraryCovers(
Directory directory,
Set<String> referencedPaths,
+6 -9
View File
@@ -1986,15 +1986,12 @@ class LibraryDatabase {
}
Future<void> delete(String id) async {
final db = await database;
await db.transaction((txn) async {
await txn.delete(
'library_path_keys',
where: 'item_id = ?',
whereArgs: [id],
);
await txn.delete('library', where: 'id = ?', whereArgs: [id]);
});
await deleteByIds([id]);
}
Future<void> deleteByIds(Iterable<String> ids) async {
if (ids.isEmpty) return;
await deleteLibraryItemsByIds(await database, ids);
}
Future<int> cleanupMissingFiles({