fix: store digital-human upload text in files, slim jsonb for list
App / Format, vet, test, and build (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Avoid pulling multi-MB result payloads on uploads?view=summary over remote DB, which caused 30s client timeouts and HTTP 500. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package resumable
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestMaterialSaveLoadAndCancelRemovesBothFiles(t *testing.T) {
|
||||
s := uploadService(t)
|
||||
ctx := uploadContext(1, "alice")
|
||||
data := []byte("material-body")
|
||||
u := create(t, s, data)
|
||||
_, err := s.Put(ctx, u.ID, 0, int64(len(data)), sum(data), strings.NewReader(string(data)))
|
||||
require.NoError(t, err)
|
||||
|
||||
source := types.DigitalHumanSource{Name: "fixture.txt", Text: strings.Repeat("正文内容-", 200)}
|
||||
require.NoError(t, s.SaveMaterial(u.ID, source))
|
||||
loaded, err := s.LoadMaterial(u.ID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, source, loaded)
|
||||
_, err = os.Stat(s.materialPath(u.ID))
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, s.Cancel(ctx, u.ID))
|
||||
_, err = os.Stat(s.path(u.ID))
|
||||
require.True(t, os.IsNotExist(err))
|
||||
_, err = os.Stat(s.materialPath(u.ID))
|
||||
require.True(t, os.IsNotExist(err))
|
||||
}
|
||||
|
||||
func TestListSummaryDoesNotTransferEmbeddedSourceText(t *testing.T) {
|
||||
s := uploadService(t)
|
||||
secret := strings.Repeat("huge-source-payload-", 8000)
|
||||
fat, err := json.Marshal(map[string]any{
|
||||
"selection": "full",
|
||||
"source": map[string]string{"name": "big.txt", "text": secret},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, s.db.Create(&Upload{
|
||||
ID: "fat-1", TenantID: 1, OwnerID: "alice", Kind: "digital-human", TargetID: "dh-1",
|
||||
Name: "big.txt", Size: 10, Offset: 10, IngestOffset: 10, State: "completed",
|
||||
Options: types.JSON(`{}`), Result: fat, ExpiresAt: time.Now().Add(time.Hour),
|
||||
}).Error)
|
||||
|
||||
rows, err := s.List(uploadContext(1, "alice"), "", "", true)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, rows, 1)
|
||||
require.JSONEq(t, `{"selection":"full"}`, string(rows[0].Result))
|
||||
require.NotContains(t, string(rows[0].Result), "huge-source-payload")
|
||||
require.Less(t, len(rows[0].Result), 64)
|
||||
|
||||
full, err := s.List(uploadContext(1, "alice"), "", "", false)
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, string(full[0].Result), secret)
|
||||
}
|
||||
|
||||
func TestCleanupRemovesMaterialFile(t *testing.T) {
|
||||
s := uploadService(t)
|
||||
ctx := uploadContext(1, "alice")
|
||||
data := []byte("x")
|
||||
u := create(t, s, data)
|
||||
_, err := s.Put(ctx, u.ID, 0, 1, sum(data), strings.NewReader("x"))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, s.SaveMaterial(u.ID, types.DigitalHumanSource{Name: "x.txt", Text: "hello"}))
|
||||
require.NoError(t, s.db.Model(&Upload{}).Where("id=?", u.ID).Update("expires_at", time.Now().Add(-time.Hour)).Error)
|
||||
require.NoError(t, s.Cleanup(ctx))
|
||||
_, err = os.Stat(s.materialPath(u.ID))
|
||||
require.True(t, os.IsNotExist(err))
|
||||
}
|
||||
Reference in New Issue
Block a user