Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix caches not being scanned in parallel on error #279

Merged
merged 1 commit into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions Assets/Script/LoadingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,39 +64,36 @@ public void QueueSongRefresh(bool fast) {
}

public void QueueSongFolderRefresh(string path) {
// Refreshes 1 folder (called when clicking "Refresh" on a folder in settings)
Queue(async () => {
await ScanSongFolder(path);
await ScanSongFolder(path, false);
});
}

private async UniTask ScanSongFolders(bool fast) {
SetLoadingText("Loading songs...");
var errors = await SongContainer.ScanAllFolders(fast, scanner => {
subPhrase.text = $"Folders Scanned: {scanner.TotalFoldersScanned}" +
$"\nSongs Scanned: {scanner.TotalSongsScanned}" +
$"\nErrors: {scanner.TotalErrorsEncountered}";
});
var errors = await SongContainer.ScanAllFolders(fast, UpdateSongUi);

// Only scan folders again on fast mode, as on slow mode they were already scanned
if (fast) {
foreach (var error in errors) {
await ScanSongFolder(error);
}
}
// Pass all errored caches in at once so it can run in parallel
await SongContainer.ScanFolders(errors, false, UpdateSongUi);
}

private async UniTask ScanSongFolder(string path) {
private async UniTask ScanSongFolder(string path, bool fast) {
SetLoadingText("Loading songs from folder...");
await SongContainer.ScanSingleFolder(path, scanner => {
subPhrase.text = $"Folders Scanned: {scanner.TotalFoldersScanned}" +
$"\nSongs Scanned: {scanner.TotalSongsScanned}" +
$"\nErrors: {scanner.TotalErrorsEncountered}";
});
await SongContainer.ScanSingleFolder(path, fast, UpdateSongUi);
}

private void SetLoadingText(string phrase, string sub = null) {
loadingPhrase.text = phrase;
subPhrase.text = sub;
}

private void UpdateSongUi(SongScanner scanner) {
string subText = $"Folders Scanned: {scanner.TotalFoldersScanned}" +
$"\nSongs Scanned: {scanner.TotalSongsScanned}" +
$"\nErrors: {scanner.TotalErrorsEncountered}";

SetLoadingText("Loading songs...", subText);
}
}
}
8 changes: 4 additions & 4 deletions Assets/Script/Song/SongContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static async UniTask<List<string>> ScanAllFolders(bool fast, Action<SongS
return output.ErroredCaches;
}

public static async UniTask ScanFolders(ICollection<string> folders, Action<SongScanner> updateUi = null) {
public static async UniTask ScanFolders(ICollection<string> folders, bool fast, Action<SongScanner> updateUi = null) {
var songsToRemove = _songs.Where(song => folders.Contains(song.CacheRoot)).ToList();

_songs.RemoveAll(x => songsToRemove.Contains(x));
Expand All @@ -55,12 +55,12 @@ public static async UniTask ScanFolders(ICollection<string> folders, Action<Song
}

var scanner = new SongScanner(folders);
var songs = await scanner.StartScan(false, updateUi);
var songs = await scanner.StartScan(fast, updateUi);

AddSongs(songs.SongEntries);
}

public static async UniTask ScanSingleFolder(string path, Action<SongScanner> updateUi = null) {
public static async UniTask ScanSingleFolder(string path, bool fast, Action<SongScanner> updateUi = null) {
var songsToRemove = _songs.Where(song => song.CacheRoot == path).ToList();

_songs.RemoveAll(x => songsToRemove.Contains(x));
Expand All @@ -69,7 +69,7 @@ public static async UniTask ScanSingleFolder(string path, Action<SongScanner> up
}

var scanner = new SongScanner(new[] { path });
var songs = await scanner.StartScan(false, updateUi);
var songs = await scanner.StartScan(fast, updateUi);

AddSongs(songs.SongEntries);
}
Expand Down