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

Memory usage improvements #3013

Merged
merged 3 commits into from
Nov 29, 2017
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
3 changes: 3 additions & 0 deletions modules/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ func (r *Repository) GetEditorconfig() (*editorconfig.Editorconfig, error) {
if err != nil {
return nil, err
}
if treeEntry.Blob().Size() >= setting.UI.MaxDisplayFileSize {
return nil, git.ErrNotExist{ID: "", RelPath: ".editorconfig"}
}
reader, err := treeEntry.Blob().Data()
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion routers/repo/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ func ServeData(ctx *context.Context, name string, reader io.Reader) error {

// ServeBlob download a git.Blob
func ServeBlob(ctx *context.Context, blob *git.Blob) error {
dataRc, err := blob.Data()
dataRc, err := blob.DataAsync()
if err != nil {
return err
}
defer dataRc.Close()

return ServeData(ctx, ctx.Repo.TreePath, dataRc)
}
Expand Down
9 changes: 7 additions & 2 deletions routers/repo/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,16 @@ func editFile(ctx *context.Context, isNewFile bool) {

// No way to edit a directory online.
if entry.IsDir() {
ctx.Handle(404, "", nil)
ctx.Handle(404, "entry.IsDir", nil)
return
}

blob := entry.Blob()
if blob.Size() >= setting.UI.MaxDisplayFileSize {
ctx.Handle(404, "blob.Size", err)
return
}

dataRc, err := blob.Data()
if err != nil {
ctx.Handle(404, "blob.Data", err)
Expand All @@ -93,7 +98,7 @@ func editFile(ctx *context.Context, isNewFile bool) {

// Only text file are editable online.
if !base.IsTextFile(buf) {
ctx.Handle(404, "", nil)
ctx.Handle(404, "base.IsTextFile", nil)
return
}

Expand Down
3 changes: 3 additions & 0 deletions routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ func getFileContentFromDefaultBranch(ctx *context.Context, filename string) (str
if err != nil {
return "", false
}
if entry.Blob().Size() >= setting.UI.MaxDisplayFileSize {
return "", false
}
r, err = entry.Blob().Data()
if err != nil {
return "", false
Expand Down
29 changes: 19 additions & 10 deletions routers/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ func renderDirectory(ctx *context.Context, treeLink string) {
ctx.Data["ReadmeInList"] = true
ctx.Data["ReadmeExist"] = true

dataRc, err := readmeFile.Data()
dataRc, err := readmeFile.DataAsync()
if err != nil {
ctx.Handle(500, "Data", err)
return
}
defer dataRc.Close()

buf := make([]byte, 1024)
n, _ := dataRc.Read(buf)
Expand All @@ -91,14 +92,21 @@ func renderDirectory(ctx *context.Context, treeLink string) {
ctx.Data["FileName"] = readmeFile.Name()
// FIXME: what happens when README file is an image?
if isTextFile {
d, _ := ioutil.ReadAll(dataRc)
buf = append(buf, d...)
if markup.Type(readmeFile.Name()) != "" {
ctx.Data["IsMarkup"] = true
ctx.Data["FileContent"] = string(markup.Render(readmeFile.Name(), buf, treeLink, ctx.Repo.Repository.ComposeMetas()))
if readmeFile.Size() >= setting.UI.MaxDisplayFileSize {
// Pretend that this is a normal text file to display 'This file is too large to be shown'
ctx.Data["IsFileTooLarge"] = true
ctx.Data["IsTextFile"] = true
ctx.Data["FileSize"] = readmeFile.Size()
} else {
ctx.Data["IsRenderedHTML"] = true
ctx.Data["FileContent"] = string(bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1))
d, _ := ioutil.ReadAll(dataRc)
buf = append(buf, d...)
if markup.Type(readmeFile.Name()) != "" {
ctx.Data["IsMarkup"] = true
ctx.Data["FileContent"] = string(markup.Render(readmeFile.Name(), buf, treeLink, ctx.Repo.Repository.ComposeMetas()))
} else {
ctx.Data["IsRenderedHTML"] = true
ctx.Data["FileContent"] = string(bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1))
}
}
}
}
Expand Down Expand Up @@ -135,11 +143,12 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
ctx.Data["IsViewFile"] = true

blob := entry.Blob()
dataRc, err := blob.Data()
dataRc, err := blob.DataAsync()
if err != nil {
ctx.Handle(500, "Data", err)
ctx.Handle(500, "DataAsync", err)
return
}
defer dataRc.Close()

ctx.Data["FileSize"] = blob.Size()
ctx.Data["FileName"] = blob.Name()
Expand Down
50 changes: 46 additions & 4 deletions vendor/code.gitea.io/git/blob.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/code.gitea.io/git/commit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/code.gitea.io/git/git.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"ignore": "test appengine",
"package": [
{
"checksumSHA1": "JN/re4+x/hCzMLGHmieUcykVDAg=",
"checksumSHA1": "vAVjAz7Wpjnu7GGba4JLIDTpQEw=",
"path": "code.gitea.io/git",
"revision": "d47b98c44c9a6472e44ab80efe65235e11c6da2a",
"revisionTime": "2017-10-23T00:52:09Z"
"revision": "f9dd6826bbb51c92c6964ce18176c304ea286e54",
"revisionTime": "2017-11-28T15:25:05Z"
},
{
"checksumSHA1": "QQ7g7B9+EIzGjO14KCGEs9TNEzM=",
Expand Down