Fix 0.62.1 server rebuild slowdown regression

Fixes #6784
This commit is contained in:
Bjørn Erik Pedersen
2020-01-22 11:57:23 +01:00
parent 2fefc01606
commit 17af79a03e
10 changed files with 186 additions and 36 deletions

View File

@@ -34,9 +34,9 @@ import (
)
const (
metaKeyFilename = "filename"
metaKeyPathFile = "pathFile" // Path of filename relative to a root.
metaKeyIsFileMount = "isFileMount" // Whether the source mount was a file.
metaKeyFilename = "filename"
metaKeyBaseDir = "baseDir" // Abs base directory of source file.
metaKeyMountRoot = "mountRoot"
metaKeyOriginalFilename = "originalFilename"
metaKeyName = "name"
@@ -116,29 +116,19 @@ func (f FileMeta) Path() string {
return f.stringV(metaKeyPath)
}
// PathFile returns the relative file path for the file source. This
// will in most cases be the same as Path.
// PathFile returns the relative file path for the file source.
func (f FileMeta) PathFile() string {
pf := f.stringV(metaKeyPathFile)
if f.isFileMount() {
return pf
base := f.stringV(metaKeyBaseDir)
if base == "" {
return ""
}
mountRoot := f.mountRoot()
if mountRoot == pf {
return f.Path()
}
return pf + (strings.TrimPrefix(f.Path(), mountRoot))
return strings.TrimPrefix(strings.TrimPrefix(f.Filename(), base), filepathSeparator)
}
func (f FileMeta) mountRoot() string {
func (f FileMeta) MountRoot() string {
return f.stringV(metaKeyMountRoot)
}
func (f FileMeta) isFileMount() bool {
return f.GetBool(metaKeyIsFileMount)
}
func (f FileMeta) Weight() int {
return f.GetInt(metaKeyWeight)
}

View File

@@ -57,12 +57,8 @@ func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error) {
// Extract "blog" from "content/blog"
rm.path = strings.TrimPrefix(strings.TrimPrefix(rm.From, fromBase), filepathSeparator)
if rm.Meta != nil {
rm.Meta[metaKeyIsFileMount] = !fi.IsDir()
rm.Meta[metaKeyBaseDir] = rm.ToBasedir
rm.Meta[metaKeyMountRoot] = rm.path
if rm.ToBasedir != "" {
pathFile := strings.TrimPrefix(strings.TrimPrefix(rm.To, rm.ToBasedir), filepathSeparator)
rm.Meta[metaKeyPathFile] = pathFile
}
}
meta := copyFileMeta(rm.Meta)

View File

@@ -271,7 +271,7 @@ func TestRootMappingFsMount(t *testing.T) {
c.Assert(singles, qt.HasLen, 2)
for i, lang := range []string{"no", "sv"} {
fi := singles[i].(FileMetaInfo)
c.Assert(fi.Meta().PathFile(), qt.Equals, lang+".txt")
c.Assert(fi.Meta().PathFile(), qt.Equals, filepath.FromSlash("themes/a/singlefiles/"+lang+".txt"))
c.Assert(fi.Meta().Lang(), qt.Equals, lang)
c.Assert(fi.Name(), qt.Equals, "p1.md")
}