Merge pull request #767 from trheyi/main

Fix memory leaks and optimize the download process.
This commit is contained in:
Max 2024-10-30 17:16:47 +08:00 committed by GitHub
commit 809c2ca612
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 54 additions and 17 deletions

View file

@ -10,10 +10,13 @@ import (
_ "github.com/yaoapp/yao/helper"
_ "github.com/yaoapp/yao/openai"
_ "github.com/yaoapp/yao/wework"
// _ "net/http/pprof"
)
// 主程序
func main() {
// go func() {
// log.Println(http.ListenAndServe("localhost:6060", nil))
// }()
utils.Init()
cmd.Execute()
}

View file

@ -57,11 +57,13 @@ func processHandler(p *action.Process, process *gouProcess.Process) (interface{}
return nil, fmt.Errorf("[dashboard] %s %s -> %s %s", dashboard.ID, p.Name, name, err.Error())
}
res, err := act.WithGlobal(process.Global).WithSID(process.Sid).Exec()
err = act.WithGlobal(process.Global).WithSID(process.Sid).Execute()
if err != nil {
log.Error("[dashboard] %s %s -> %s %s", dashboard.ID, p.Name, name, err.Error())
return nil, fmt.Errorf("[dashboard] %s %s -> %s %s", dashboard.ID, p.Name, name, err.Error())
}
defer act.Release()
res := act.Value()
// Compute View
err = dashboard.ComputeView(p.Name, process, res, dashboard.getField())

View file

@ -1,6 +1,7 @@
package dashboard
import (
"fmt"
"net/url"
"testing"
@ -45,6 +46,8 @@ func TestProcessComponent(t *testing.T) {
t.Fatal(err)
}
fmt.Println(res)
pets, ok := res.([]maps.MapStr)
assert.True(t, ok)
assert.Equal(t, 2, len(pets))

View file

@ -63,11 +63,13 @@ func processHandler(p *action.Process, process *gouProcess.Process) (interface{}
return nil, fmt.Errorf("[form] %s %s -> %s %s", form.ID, p.Name, name, err.Error())
}
res, err := act.WithGlobal(process.Global).WithSID(process.Sid).Exec()
err = act.WithGlobal(process.Global).WithSID(process.Sid).Execute()
if err != nil {
log.Error("[form] %s %s -> %s %s", form.ID, p.Name, name, err.Error())
return nil, fmt.Errorf("[form] %s %s -> %s %s", form.ID, p.Name, name, err.Error())
}
defer act.Release()
res := act.Value()
// Compute View
err = form.ComputeView(p.Name, process, res, form.getField())

View file

@ -118,13 +118,13 @@ func processDownload(process *gouProcess.Process) interface{} {
}
// Excute process
res, err := p.WithGlobal(process.Global).WithSID(claims.SID).Exec()
err = p.WithGlobal(process.Global).WithSID(claims.SID).Execute()
if err != nil {
log.Error("[downalod] %s.%s %s", form.ID, field, err.Error())
exception.New("[downalod] %s.%s %s", 500, form.ID, field, err.Error()).Throw()
}
return res
defer p.Release()
return p.Value()
}
func processUpload(process *gouProcess.Process) interface{} {

View file

@ -2,6 +2,7 @@ package form
import (
"fmt"
"io"
"net/url"
"os"
"testing"
@ -152,7 +153,8 @@ func TestProcessDelete(t *testing.T) {
t.Fatal(err)
}
_, err = process.New("yao.form.find", "pet", 1).Exec()
res, err := process.New("yao.form.find", "pet", 1).Exec()
fmt.Println("err", res, err)
assert.Contains(t, err.Error(), "ID=1")
}
@ -251,8 +253,18 @@ func TestProcessDownload(t *testing.T) {
}
body, ok := res.(map[string]interface{})
reader, ok := body["content"].(io.ReadCloser)
if !ok {
t.Fatal("content not found")
}
defer reader.Close()
content, err := io.ReadAll(reader)
if err != nil {
t.Fatal(err)
}
assert.True(t, ok)
assert.Equal(t, []byte("Hello"), body["content"])
assert.Equal(t, []byte("Hello"), content)
assert.Equal(t, "text/plain; charset=utf-8", body["type"])
}

View file

@ -63,11 +63,13 @@ func processHandler(p *action.Process, process *gouProcess.Process) (interface{}
return nil, fmt.Errorf("[list] %s %s -> %s %s", list.ID, p.Name, name, err.Error())
}
res, err := act.WithGlobal(process.Global).WithSID(process.Sid).Exec()
err = act.WithGlobal(process.Global).WithSID(process.Sid).Execute()
if err != nil {
log.Error("[list] %s %s -> %s %s", list.ID, p.Name, name, err.Error())
return nil, fmt.Errorf("[list] %s %s -> %s %s", list.ID, p.Name, name, err.Error())
}
defer act.Release()
res := act.Value()
// Compute View
err = list.ComputeView(p.Name, process, res, list.getField())

View file

@ -100,13 +100,13 @@ func processDownload(process *gouProcess.Process) interface{} {
}
// Excute process
res, err := p.WithGlobal(process.Global).WithSID(claims.SID).Exec()
err = p.WithGlobal(process.Global).WithSID(claims.SID).Execute()
if err != nil {
log.Error("[downalod] %s.%s %s", list.ID, field, err.Error())
exception.New("[downalod] %s.%s %s", 500, list.ID, field, err.Error()).Throw()
}
return res
defer p.Release()
return p.Value()
}
func processUpload(process *gouProcess.Process) interface{} {

View file

@ -70,11 +70,13 @@ func processHandler(p *action.Process, process *gouProcess.Process) (interface{}
return nil, fmt.Errorf("[table] %s %s -> %s %s", tab.ID, p.Name, name, err.Error())
}
res, err := act.WithGlobal(process.Global).WithSID(process.Sid).Exec()
err = act.WithGlobal(process.Global).WithSID(process.Sid).Execute()
if err != nil {
log.Error("[table] %s %s -> %s %s %v", tab.ID, p.Name, name, err.Error(), args)
return nil, fmt.Errorf("[table] %s %s -> %s %s", tab.ID, p.Name, name, err.Error())
}
defer act.Release()
res := act.Value()
// Compute View
err = tab.ComputeView(p.Name, process, res, tab.getField())

View file

@ -103,13 +103,13 @@ func processDownload(process *gouProcess.Process) interface{} {
}
// Excute process
res, err := p.WithGlobal(process.Global).WithSID(claims.SID).Exec()
err = p.WithGlobal(process.Global).WithSID(claims.SID).Execute()
if err != nil {
log.Error("[downalod] %s.%s %s", tab.ID, field, err.Error())
exception.New("[downalod] %s.%s %s", 500, tab.ID, field, err.Error()).Throw()
}
return res
defer p.Release()
return p.Value()
}
func processUpload(process *gouProcess.Process) interface{} {

View file

@ -2,6 +2,7 @@ package table
import (
"fmt"
"io"
"net/url"
"os"
"testing"
@ -451,8 +452,18 @@ func TestProcessDownload(t *testing.T) {
}
body, ok := res.(map[string]interface{})
reader, ok := body["content"].(io.ReadCloser)
if !ok {
t.Fatal("content not found")
}
defer reader.Close()
content, err := io.ReadAll(reader)
if err != nil {
t.Fatal(err)
}
assert.True(t, ok)
assert.Equal(t, []byte("Hello"), body["content"])
assert.Equal(t, []byte("Hello"), content)
assert.Equal(t, "text/plain; charset=utf-8", body["type"])
}