-
Notifications
You must be signed in to change notification settings - Fork 784
fix: file browser shows newest files first, bump limit to 5000 #2856
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import ( | |
| "log" | ||
| "os" | ||
| "path/filepath" | ||
| "sort" | ||
| "strings" | ||
| "time" | ||
|
|
||
|
|
@@ -57,6 +58,17 @@ func (impl *ServerImpl) remoteStreamFileDir(ctx context.Context, path string, by | |
| if err != nil { | ||
| return fmt.Errorf("cannot open dir %q: %w", path, err) | ||
| } | ||
| sort.Slice(innerFilesEntries, func(i, j int) bool { | ||
| iInfo, iErr := innerFilesEntries[i].Info() | ||
| jInfo, jErr := innerFilesEntries[j].Info() | ||
| if iErr != nil { | ||
| return false | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WARNING: Inconsistent error handling in sort comparator When Consider handling both error cases consistently, such as:
|
||
| } | ||
| if jErr != nil { | ||
| return true | ||
| } | ||
| return iInfo.ModTime().After(jInfo.ModTime()) | ||
| }) | ||
| if byteRange.All { | ||
| if len(innerFilesEntries) > wshrpc.MaxDirSize { | ||
| innerFilesEntries = innerFilesEntries[:wshrpc.MaxDirSize] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: Performance concern with sorting large directories
Calling
.Info()on every entry during each comparison can be expensive. With the newMaxDirSizeof 5000, sorting could trigger up to ~10,000 system calls (each comparison callsInfo()twice, and sorting requires O(n log n) comparisons).Consider caching the
FileInforesults before sorting: