作者 yangfu

feat: table data cache v1

... ... @@ -42,7 +42,7 @@ func (querySetService *QuerySetService) CalculateSetPreview(ctx *domain.Context,
response.ObjectType = querySet.Type
response.Name = querySet.Name
response.Fields = dataTable.Fields
response.Data = domain.GripData(domain.ToFieldData(dataTable.Fields, dataTable.Data, false), int64(len(dataTable.Data)))
response.Data = domain.GripData(domain.ToFieldData(dataTable.Fields, dataTable.Data, false, true), int64(len(dataTable.Data)))
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -203,9 +203,13 @@ func ValueToType(value string, sqlType string) (interface{}, error) {
return toTypeVal, err
}
func ToFieldData(fields []*Field, data [][]string, byName bool) []map[string]string {
func ToFieldData(fields []*Field, data [][]string, byName bool, configs ...bool) []map[string]string {
var result = make([]map[string]string, 0)
var key string
var ignoreEmptyString = false
if len(configs) > 0 {
ignoreEmptyString = configs[0]
}
for _, d := range data {
var item = make(map[string]string)
for j, f := range fields {
... ... @@ -213,6 +217,9 @@ func ToFieldData(fields []*Field, data [][]string, byName bool) []map[string]str
if byName {
key = f.Name
}
if ignoreEmptyString && len(d[j]) == 0 {
continue
}
if len(d) >= j {
item[key] = d[j]
} else {
... ...
... ... @@ -10,8 +10,8 @@ import (
"strings"
)
const DefaultExpandNum = 10000
const MaxExpandNum = 50000
const DefaultExpandNum = 1000
const MaxExpandNum = 5000
func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain.QuerySet, queryComponents []*domain.QueryComponent) (*domain.DataTable, error) {
var (
... ... @@ -41,7 +41,7 @@ func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain
// 根据数据修改便宜
CellsLocationAdjust(cells)
// 数据布局
res, err = DataLayout(res, dataTables, cells)
res, err = DataLayout(res, cells)
if err != nil {
return nil, err
}
... ... @@ -60,18 +60,6 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) {
yMin = cells[0].Y
yMax = cells[0].Y
}
min := func(a, b int) int {
if a > b {
return b
}
return a
}
max := func(a, b int) int {
if a < b {
return b
}
return a
}
for i := 1; i <= len(cells)-1; i++ {
cell := cells[i]
xMin = min(xMin, cell.X)
... ... @@ -205,7 +193,7 @@ func (ptr *QuerySetService) LoadDataTables(ctx *domain.Context, cells []*domain.
return dataTables
}
func DataLayout(res *domain.DataTable, dataTables map[int]*domain.DataTable, cells []*domain.LayoutCell) (*domain.DataTable, error) {
func DataLayout(res *domain.DataTable, cells []*domain.LayoutCell) (*domain.DataTable, error) {
dt := &DataLayoutDataTable{
DataTable: res,
//MapDataTables: dataTables,
... ... @@ -273,10 +261,19 @@ func (l *Location) UpdateY(y int) {
}
}
func (d *DataLayoutDataTable) StartCell() {
func (l *Location) Update(x int, y int, compare func(int, int) int) {
if x != 0 {
l.X = compare(l.X, x)
}
if y != 0 {
l.Y = compare(l.Y, y)
}
}
//func (d *DataLayoutDataTable) StartCell() {
//
//}
func (d *DataLayoutDataTable) addByLocation(cell *domain.LayoutCell, blockData []string) {
if d.PointBegin == nil {
d.PointBegin = NewLocation(cell.X, cell.Y)
... ... @@ -287,18 +284,21 @@ func (d *DataLayoutDataTable) addByLocation(cell *domain.LayoutCell, blockData [
for i := range blockData {
d.DataTable.Data[cell.X][cell.Y+i] = blockData[i]
}
d.PointEnd.UpdateX(cell.X)
d.PointEnd.UpdateY(cell.Y + len(blockData) - 1)
//d.PointEnd.UpdateX(cell.X)
//d.PointEnd.UpdateY(cell.Y + len(blockData) - 1)
d.PointEnd.Update(cell.X, cell.Y+len(blockData)-1, max)
case domain.DirectionDown:
for i := range blockData {
d.DataTable.Data[cell.X+i][cell.Y] = blockData[i]
}
d.PointEnd.UpdateX(cell.X + len(blockData) - 1)
d.PointEnd.UpdateY(cell.Y)
//d.PointEnd.UpdateX(cell.X + len(blockData) - 1)
//d.PointEnd.UpdateY(cell.Y)
d.PointEnd.Update(cell.X+len(blockData)-1, cell.Y, max)
case domain.DirectionNone:
d.DataTable.Data[cell.X][cell.Y] = blockData[0]
d.PointEnd.UpdateX(cell.X)
d.PointEnd.UpdateY(cell.Y)
//d.PointEnd.UpdateX(cell.X)
//d.PointEnd.UpdateY(cell.Y)
d.PointEnd.Update(cell.X, cell.Y, max)
}
}
... ... @@ -411,3 +411,16 @@ func (d *DataLayoutDataTable) CellOutRange(cell *domain.LayoutCell, length int)
}
return false
}
func min(a, b int) int {
if a > b {
return b
}
return a
}
func max(a, b int) int {
if a < b {
return b
}
return a
}
... ...
... ... @@ -451,7 +451,7 @@ func TestDataLayout(t *testing.T) {
CellsLocationAdjust(input.cells)
// 数据布局
res := &domain.DataTable{}
res, err := DataLayout(res, nil, input.cells)
res, err := DataLayout(res, input.cells)
if err != nil {
assert.NoError(t, err)
}
... ...