Skip to content

Commit 997b820

Browse files
authored
perf: use gzipped data for improved load speed in large response (#11128)
* perf: use gzipped data for improved load speed in big files * perf: switch to gzipped response for GetFileTree to enhance performance * perf: switch to gzipped response for SearchApp to improve performance * perf: update file size conditions for gzipped response to enhance performance
1 parent 5de8398 commit 997b820

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

agent/app/api/v2/app.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package v2
22

33
import (
4+
"net/http"
5+
"time"
6+
47
"github.com/1Panel-dev/1Panel/agent/app/api/v2/helper"
58
"github.com/1Panel-dev/1Panel/agent/app/dto"
69
"github.com/1Panel-dev/1Panel/agent/app/dto/request"
710
"github.com/1Panel-dev/1Panel/agent/i18n"
811
"github.com/gin-gonic/gin"
9-
"net/http"
10-
"time"
1112
)
1213

1314
// @Tags App
@@ -28,7 +29,7 @@ func (b *BaseApi) SearchApp(c *gin.Context) {
2829
helper.InternalServer(c, err)
2930
return
3031
}
31-
helper.SuccessWithData(c, list)
32+
helper.SuccessWithDataGzipped(c, list)
3233
}
3334

3435
// @Tags App

agent/app/api/v2/dashboard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (b *BaseApi) LoadAppLauncher(c *gin.Context) {
3737
helper.InternalServer(c, err)
3838
return
3939
}
40-
helper.SuccessWithData(c, data)
40+
helper.SuccessWithDataGzipped(c, data)
4141
}
4242

4343
// @Tags Dashboard

agent/app/api/v2/file.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (b *BaseApi) GetFileTree(c *gin.Context) {
9090
helper.InternalServer(c, err)
9191
return
9292
}
93-
helper.SuccessWithData(c, tree)
93+
helper.SuccessWithDataGzipped(c, tree)
9494
}
9595

9696
// @Tags File
@@ -265,7 +265,11 @@ func (b *BaseApi) GetContent(c *gin.Context) {
265265
helper.InternalServer(c, err)
266266
return
267267
}
268-
helper.SuccessWithData(c, info)
268+
if info.Size > 2*1024 && info.Size < 5*1024*1024 {
269+
helper.SuccessWithDataGzipped(c, info)
270+
} else {
271+
helper.SuccessWithData(c, info)
272+
}
269273
}
270274

271275
// @Tags File

agent/app/api/v2/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (b *BaseApi) LoadMonitor(c *gin.Context) {
2828
helper.InternalServer(c, err)
2929
return
3030
}
31-
helper.SuccessWithData(c, data)
31+
helper.SuccessWithDataGzipped(c, data)
3232
}
3333

3434
// @Tags Monitor

agent/app/api/v2/website_ssl.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package v2
22

33
import (
4-
"github.com/1Panel-dev/1Panel/agent/app/model"
54
"io"
65
"mime/multipart"
76
"net/http"
87
"net/url"
98
"reflect"
109
"strconv"
1110

11+
"github.com/1Panel-dev/1Panel/agent/app/model"
12+
1213
"github.com/1Panel-dev/1Panel/agent/app/api/v2/helper"
1314
"github.com/1Panel-dev/1Panel/agent/app/dto"
1415
"github.com/1Panel-dev/1Panel/agent/app/dto/request"
@@ -34,7 +35,7 @@ func (b *BaseApi) PageWebsiteSSL(c *gin.Context) {
3435
helper.InternalServer(c, err)
3536
return
3637
}
37-
helper.SuccessWithData(c, dto.PageResult{
38+
helper.SuccessWithDataGzipped(c, dto.PageResult{
3839
Total: total,
3940
Items: accounts,
4041
})
@@ -44,7 +45,7 @@ func (b *BaseApi) PageWebsiteSSL(c *gin.Context) {
4445
helper.InternalServer(c, err)
4546
return
4647
}
47-
helper.SuccessWithData(c, list)
48+
helper.SuccessWithDataGzipped(c, list)
4849
}
4950
}
5051

0 commit comments

Comments
 (0)