From 760cdb50d77f20299d73df3ad17a141fa1099f24 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 18 May 2023 13:50:13 +0800 Subject: [PATCH] Optimize yao.table.Export --- widgets/table/process.go | 8 +++----- widgets/table/process_test.go | 7 +++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/widgets/table/process.go b/widgets/table/process.go index b90bc685..0dbf8a01 100644 --- a/widgets/table/process.go +++ b/widgets/table/process.go @@ -1,8 +1,6 @@ package table import ( - "crypto/md5" - "encoding/hex" "fmt" "net/url" "os" @@ -10,6 +8,7 @@ import ( "strings" "time" + "github.com/google/uuid" "github.com/yaoapp/gou/fs" "github.com/yaoapp/gou/model" gouProcess "github.com/yaoapp/gou/process" @@ -252,11 +251,10 @@ func processExport(process *gouProcess.Process) interface{} { tab := MustGet(process) // 0 params := process.ArgsQueryParams(1, types.QueryParam{}) pagesize := process.ArgsInt(2, 50) + log.Trace("[table] export %s %v %d", tab.ID, params, pagesize) // Filename - hash := md5.Sum([]byte(time.Now().Format("20060102-15:04:05"))) - fingerprint := string(hex.EncodeToString(hash[:])) - fingerprint = strings.ToUpper(fingerprint) + fingerprint := uuid.NewString() dir := time.Now().Format("20060102") filename := filepath.Join(string(os.PathSeparator), dir, fmt.Sprintf("%s.xlsx", fingerprint)) diff --git a/widgets/table/process_test.go b/widgets/table/process_test.go index 3bdb5c28..28d724b4 100644 --- a/widgets/table/process_test.go +++ b/widgets/table/process_test.go @@ -569,6 +569,13 @@ func TestProcessExport(t *testing.T) { fs := fs.MustGet("system") size, _ := fs.Size(response.(string)) assert.Greater(t, size, 1000) + + // Export all data + args = []interface{}{"pet", nil, 2} + response = process.New("yao.table.Export", args...).Run() + assert.NotNil(t, response) + size, _ = fs.Size(response.(string)) + assert.Greater(t, size, 1000) } func load(t *testing.T) {