cleanup history entries after db update
- delete history entries without album/artist - fix #37
This commit is contained in:
parent
9c615dde02
commit
cd068c9579
3 changed files with 41 additions and 0 deletions
|
@ -418,4 +418,41 @@ class MusicDataDao extends DatabaseAccessor<MoorDatabase>
|
||||||
batch.deleteWhere<$BlockedFilesTable, dynamic>(blockedFiles, (tbl) => tbl.path.isIn(paths));
|
batch.deleteWhere<$BlockedFilesTable, dynamic>(blockedFiles, (tbl) => tbl.path.isIn(paths));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> cleanupDatabase() async {
|
||||||
|
// get album history entries
|
||||||
|
final albumHistoryEntries = await (select(historyEntries)
|
||||||
|
..where((tbl) => tbl.type.equals(PlayableType.album.toString())))
|
||||||
|
.get();
|
||||||
|
|
||||||
|
// delete history entries with missing album
|
||||||
|
for (final entry in albumHistoryEntries) {
|
||||||
|
if ((await (select(albums)..where((tbl) => tbl.id.equals(int.parse(entry.identifier)))).get())
|
||||||
|
.isEmpty) {
|
||||||
|
(delete(historyEntries)
|
||||||
|
..where((tbl) =>
|
||||||
|
tbl.type.equals(PlayableType.album.toString()) &
|
||||||
|
tbl.identifier.equals(entry.identifier)))
|
||||||
|
.go();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// get album history entries
|
||||||
|
final artistHistoryEntries = await (select(historyEntries)
|
||||||
|
..where((tbl) => tbl.type.equals(PlayableType.artist.toString())))
|
||||||
|
.get();
|
||||||
|
|
||||||
|
// delete history entries with missing album
|
||||||
|
for (final entry in artistHistoryEntries) {
|
||||||
|
if ((await (select(artists)..where((tbl) => tbl.id.equals(int.parse(entry.identifier)))).get())
|
||||||
|
.isEmpty) {
|
||||||
|
(delete(historyEntries)
|
||||||
|
..where((tbl) =>
|
||||||
|
tbl.type.equals(PlayableType.artist.toString()) &
|
||||||
|
tbl.identifier.equals(entry.identifier)))
|
||||||
|
.go();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,4 +39,6 @@ abstract class MusicDataSource {
|
||||||
Stream<Set<String>> get blockedFilesStream;
|
Stream<Set<String>> get blockedFilesStream;
|
||||||
Future<void> addBlockedFiles(List<String> paths);
|
Future<void> addBlockedFiles(List<String> paths);
|
||||||
Future<void> removeBlockedFiles(List<String> paths);
|
Future<void> removeBlockedFiles(List<String> paths);
|
||||||
|
|
||||||
|
Future<void> cleanupDatabase();
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,6 +128,8 @@ class MusicDataRepositoryImpl implements MusicDataRepository {
|
||||||
await _updateAlbums(albums);
|
await _updateAlbums(albums);
|
||||||
await _musicDataSource.insertSongs(songs);
|
await _musicDataSource.insertSongs(songs);
|
||||||
|
|
||||||
|
await _musicDataSource.cleanupDatabase();
|
||||||
|
|
||||||
_log.d('updateDatabase finished');
|
_log.d('updateDatabase finished');
|
||||||
|
|
||||||
_updateHighlightStreams();
|
_updateHighlightStreams();
|
||||||
|
|
Loading…
Add table
Reference in a new issue