Merge pull request #767 from trheyi/main
Fix memory leaks and optimize the download process.
This commit is contained in:
commit
809c2ca612
11 changed files with 54 additions and 17 deletions
5
main.go
5
main.go
|
|
@ -10,10 +10,13 @@ import (
|
||||||
_ "github.com/yaoapp/yao/helper"
|
_ "github.com/yaoapp/yao/helper"
|
||||||
_ "github.com/yaoapp/yao/openai"
|
_ "github.com/yaoapp/yao/openai"
|
||||||
_ "github.com/yaoapp/yao/wework"
|
_ "github.com/yaoapp/yao/wework"
|
||||||
|
// _ "net/http/pprof"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 主程序
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// go func() {
|
||||||
|
// log.Println(http.ListenAndServe("localhost:6060", nil))
|
||||||
|
// }()
|
||||||
utils.Init()
|
utils.Init()
|
||||||
cmd.Execute()
|
cmd.Execute()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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())
|
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 {
|
if err != nil {
|
||||||
log.Error("[dashboard] %s %s -> %s %s", dashboard.ID, p.Name, name, err.Error())
|
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())
|
return nil, fmt.Errorf("[dashboard] %s %s -> %s %s", dashboard.ID, p.Name, name, err.Error())
|
||||||
}
|
}
|
||||||
|
defer act.Release()
|
||||||
|
res := act.Value()
|
||||||
|
|
||||||
// Compute View
|
// Compute View
|
||||||
err = dashboard.ComputeView(p.Name, process, res, dashboard.getField())
|
err = dashboard.ComputeView(p.Name, process, res, dashboard.getField())
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package dashboard
|
package dashboard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -45,6 +46,8 @@ func TestProcessComponent(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println(res)
|
||||||
|
|
||||||
pets, ok := res.([]maps.MapStr)
|
pets, ok := res.([]maps.MapStr)
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
assert.Equal(t, 2, len(pets))
|
assert.Equal(t, 2, len(pets))
|
||||||
|
|
|
||||||
|
|
@ -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())
|
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 {
|
if err != nil {
|
||||||
log.Error("[form] %s %s -> %s %s", form.ID, p.Name, name, err.Error())
|
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())
|
return nil, fmt.Errorf("[form] %s %s -> %s %s", form.ID, p.Name, name, err.Error())
|
||||||
}
|
}
|
||||||
|
defer act.Release()
|
||||||
|
res := act.Value()
|
||||||
|
|
||||||
// Compute View
|
// Compute View
|
||||||
err = form.ComputeView(p.Name, process, res, form.getField())
|
err = form.ComputeView(p.Name, process, res, form.getField())
|
||||||
|
|
|
||||||
|
|
@ -118,13 +118,13 @@ func processDownload(process *gouProcess.Process) interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Excute process
|
// Excute process
|
||||||
res, err := p.WithGlobal(process.Global).WithSID(claims.SID).Exec()
|
err = p.WithGlobal(process.Global).WithSID(claims.SID).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("[downalod] %s.%s %s", form.ID, field, err.Error())
|
log.Error("[downalod] %s.%s %s", form.ID, field, err.Error())
|
||||||
exception.New("[downalod] %s.%s %s", 500, form.ID, field, err.Error()).Throw()
|
exception.New("[downalod] %s.%s %s", 500, form.ID, field, err.Error()).Throw()
|
||||||
}
|
}
|
||||||
|
defer p.Release()
|
||||||
return res
|
return p.Value()
|
||||||
}
|
}
|
||||||
|
|
||||||
func processUpload(process *gouProcess.Process) interface{} {
|
func processUpload(process *gouProcess.Process) interface{} {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package form
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -152,7 +153,8 @@ func TestProcessDelete(t *testing.T) {
|
||||||
t.Fatal(err)
|
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")
|
assert.Contains(t, err.Error(), "ID=1")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -251,8 +253,18 @@ func TestProcessDownload(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
body, ok := res.(map[string]interface{})
|
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.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"])
|
assert.Equal(t, "text/plain; charset=utf-8", body["type"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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())
|
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 {
|
if err != nil {
|
||||||
log.Error("[list] %s %s -> %s %s", list.ID, p.Name, name, err.Error())
|
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())
|
return nil, fmt.Errorf("[list] %s %s -> %s %s", list.ID, p.Name, name, err.Error())
|
||||||
}
|
}
|
||||||
|
defer act.Release()
|
||||||
|
res := act.Value()
|
||||||
|
|
||||||
// Compute View
|
// Compute View
|
||||||
err = list.ComputeView(p.Name, process, res, list.getField())
|
err = list.ComputeView(p.Name, process, res, list.getField())
|
||||||
|
|
|
||||||
|
|
@ -100,13 +100,13 @@ func processDownload(process *gouProcess.Process) interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Excute process
|
// Excute process
|
||||||
res, err := p.WithGlobal(process.Global).WithSID(claims.SID).Exec()
|
err = p.WithGlobal(process.Global).WithSID(claims.SID).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("[downalod] %s.%s %s", list.ID, field, err.Error())
|
log.Error("[downalod] %s.%s %s", list.ID, field, err.Error())
|
||||||
exception.New("[downalod] %s.%s %s", 500, list.ID, field, err.Error()).Throw()
|
exception.New("[downalod] %s.%s %s", 500, list.ID, field, err.Error()).Throw()
|
||||||
}
|
}
|
||||||
|
defer p.Release()
|
||||||
return res
|
return p.Value()
|
||||||
}
|
}
|
||||||
|
|
||||||
func processUpload(process *gouProcess.Process) interface{} {
|
func processUpload(process *gouProcess.Process) interface{} {
|
||||||
|
|
|
||||||
|
|
@ -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())
|
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 {
|
if err != nil {
|
||||||
log.Error("[table] %s %s -> %s %s %v", tab.ID, p.Name, name, err.Error(), args)
|
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())
|
return nil, fmt.Errorf("[table] %s %s -> %s %s", tab.ID, p.Name, name, err.Error())
|
||||||
}
|
}
|
||||||
|
defer act.Release()
|
||||||
|
res := act.Value()
|
||||||
|
|
||||||
// Compute View
|
// Compute View
|
||||||
err = tab.ComputeView(p.Name, process, res, tab.getField())
|
err = tab.ComputeView(p.Name, process, res, tab.getField())
|
||||||
|
|
|
||||||
|
|
@ -103,13 +103,13 @@ func processDownload(process *gouProcess.Process) interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Excute process
|
// Excute process
|
||||||
res, err := p.WithGlobal(process.Global).WithSID(claims.SID).Exec()
|
err = p.WithGlobal(process.Global).WithSID(claims.SID).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("[downalod] %s.%s %s", tab.ID, field, err.Error())
|
log.Error("[downalod] %s.%s %s", tab.ID, field, err.Error())
|
||||||
exception.New("[downalod] %s.%s %s", 500, tab.ID, field, err.Error()).Throw()
|
exception.New("[downalod] %s.%s %s", 500, tab.ID, field, err.Error()).Throw()
|
||||||
}
|
}
|
||||||
|
defer p.Release()
|
||||||
return res
|
return p.Value()
|
||||||
}
|
}
|
||||||
|
|
||||||
func processUpload(process *gouProcess.Process) interface{} {
|
func processUpload(process *gouProcess.Process) interface{} {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package table
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -451,8 +452,18 @@ func TestProcessDownload(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
body, ok := res.(map[string]interface{})
|
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.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"])
|
assert.Equal(t, "text/plain; charset=utf-8", body["type"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue