Skip to content

Commit

Permalink
More improvements
Browse files Browse the repository at this point in the history
InjectFileSource
1. Increase possible batch size
2. Use Interlock.Increment

Delete to Recycle Bin
1. Improve FileInfoSource removal speed
  • Loading branch information
bagusnl committed Dec 19, 2024
1 parent 5edc9c6 commit 32c6cae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 13 additions & 11 deletions CollapseLauncher/XAMLs/MainApp/Pages/FileCleanupPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public async Task InjectFileInfoSource(IEnumerable<LocalFileInfo> fileInfoList)

FileInfoSource.Clear();
_assetTotalSize = 0;
int batchSize = Math.Clamp(FileInfoSource.Count / (Environment.ProcessorCount * 4), 50, 1000);

_localFileCollection = new ObservableCollection<LocalFileInfo>(fileInfoList);

int batchSize = Math.Clamp(_localFileCollection.Count / Environment.ProcessorCount, 50, 5000);

var batches = _localFileCollection
.Select((file, index) => new { File = file, Index = index })
.GroupBy(x => x.Index / batchSize)
Expand All @@ -86,9 +86,8 @@ await Task.Run(() =>
_localFileCollection.Remove(fileInfoInner);
}
sI.Stop();
Logger.LogWriteLine($"[FileCleanupPage::InjectFileInfoSource] Finished batch #{b} with {batch.Count} items after {s.ElapsedMilliseconds} ms", LogType.Scheme);
b++;
sI = null;
Logger.LogWriteLine($"[FileCleanupPage::InjectFileInfoSource] Finished batch #{b} with {batch.Count} items after {sI.ElapsedMilliseconds} ms", LogType.Scheme);
Interlocked.Increment(ref b);
}));

}
Expand Down Expand Up @@ -129,7 +128,7 @@ await EnqueueOnDispatcherQueueAsync(() =>

if (ListViewTable.Items.Count < 1000)
{
CheckAll();
await CheckAll();
}
else
{
Expand Down Expand Up @@ -165,17 +164,19 @@ private async void ToggleCheckAll(object sender, RoutedEventArgs e)
LoadingMessageHelper.SetMessage(Locale.Lang._FileCleanupPage.LoadingTitle, "UI might freeze for a moment...");
await Task.Delay(100);
s.Start();
bool toCheckCopy = false;
if (sender is CheckBox checkBox)
{
bool toCheck = checkBox.IsChecked ?? false;
await ToggleCheckAllInnerAsync(toCheck);
toCheckCopy = toCheck;
}
s.Stop();
LoadingMessageHelper.HideLoadingFrame();
Logger.LogWriteLine("[FileCleanupPage::ToggleCheckAll] Elapsed time: " + s.ElapsedMilliseconds + "ms", LogType.Scheme);
Logger.LogWriteLine($"[FileCleanupPage::ToggleCheckAll{toCheckCopy}] Elapsed time: {s.ElapsedMilliseconds} ms", LogType.Scheme);
}

private async void CheckAll()
private async Task CheckAll()
{
await ToggleCheckAllInnerAsync(true);
}
Expand All @@ -184,11 +185,11 @@ private async Task ToggleCheckAllInnerAsync(bool selectAll)
{
if (selectAll)
{
await EnqueueOnDispatcherQueueAsync(() => ListViewTable.SelectAll());
await EnqueueOnDispatcherQueueAsync(() => ListViewTable.SelectAllSafe());
}
else
{
await EnqueueOnDispatcherQueueAsync(() => ListViewTable.SelectedItems.Clear());
await EnqueueOnDispatcherQueueAsync(() => ListViewTable.DeselectAll());
}
}

Expand Down Expand Up @@ -369,9 +370,10 @@ private async Task PerformRemoval(ICollection<LocalFileInfo>? deletionSource, lo
await Task.Run(() => RecycleBin.MoveFileToRecycleBin(toBeDeleted));
DispatcherQueue.TryEnqueue(() =>
{
var toBeDeletedSet = new HashSet<string>(toBeDeleted);
for (int i = FileInfoSource.Count - 1; i >= 0; i--)
{
if (toBeDeleted.Contains(FileInfoSource[i].ToFileInfo().FullName))
if (toBeDeletedSet.Contains(FileInfoSource[i].FullPath))
{
FileInfoSource.RemoveAt(i);
}
Expand Down
2 changes: 1 addition & 1 deletion Hi3Helper.EncTool

0 comments on commit 32c6cae

Please sign in to comment.