mirror of https://github.com/cheat/cheat.git
perf(Sheets): do not walk hidden directories
Modify `Sheets.Load` to not walk hidden directories like `.git`. This optimization can potentially prevent thousands of system calls from being made, because `.git` directories can contain many files.
This commit is contained in:
parent
cfd1702bc6
commit
484b447391
|
@ -2,6 +2,7 @@ package sheets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -55,7 +56,11 @@ func Load(cheatpaths []cp.Cheatpath) ([]map[string]sheet.Sheet, error) {
|
||||||
// contained within hidden directories in the middle of a path, though
|
// contained within hidden directories in the middle of a path, though
|
||||||
// that should not realistically occur.
|
// that should not realistically occur.
|
||||||
if strings.HasPrefix(title, ".") || strings.HasPrefix(info.Name(), ".") {
|
if strings.HasPrefix(title, ".") || strings.HasPrefix(info.Name(), ".") {
|
||||||
return nil
|
// Do not walk hidden directories. This is important,
|
||||||
|
// because it's common for cheatsheets to be stored in
|
||||||
|
// version-control, and a `.git` directory can easily
|
||||||
|
// contain thousands of files.
|
||||||
|
return fs.SkipDir
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the cheatsheet file into a `sheet` struct
|
// parse the cheatsheet file into a `sheet` struct
|
||||||
|
|
Loading…
Reference in New Issue