mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-29 21:02:09 +02:00
perf(library): batch album deletion and refresh once
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user