mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
Merge pull request #1471 from wanyaoqi/bugfix/wyq/fix-export-data
bugfix: fix export data, set no limit; expand timeout
This commit is contained in:
@@ -245,7 +245,7 @@ func (app *Application) defaultHandle(w http.ResponseWriter, r *http.Request, ri
|
||||
if ok {
|
||||
fw := newResponseWriterChannel(w)
|
||||
worker := make(chan *SWorker)
|
||||
to := hand.processTimeout
|
||||
to := hand.FetchProcessTimeout(r)
|
||||
if to == 0 {
|
||||
to = app.processTimeout
|
||||
}
|
||||
|
||||
@@ -41,6 +41,14 @@ type SHandlerInfo struct {
|
||||
skipLog bool
|
||||
}
|
||||
|
||||
func (this *SHandlerInfo) FetchProcessTimeout(r *http.Request) time.Duration {
|
||||
if r.Method == http.MethodGet && r.Header.Get("X-Export-Keys") == "true" {
|
||||
return time.Hour * 2
|
||||
} else {
|
||||
return this.processTimeout
|
||||
}
|
||||
}
|
||||
|
||||
func (this *SHandlerInfo) GetName(params map[string]string) string {
|
||||
if len(this.name) > 0 {
|
||||
return this.name
|
||||
|
||||
@@ -476,6 +476,12 @@ func ListItems(manager IModelManager, ctx context.Context, userCred mcclient.Tok
|
||||
limit = maxLimit
|
||||
}
|
||||
|
||||
// export data only
|
||||
exportLimit, err := query.Int("export_limit")
|
||||
if query.Contains("export_keys") && err == nil {
|
||||
limit = exportLimit
|
||||
}
|
||||
|
||||
var primaryCol sqlchemy.IColumnSpec
|
||||
primaryCols := manager.TableSpec().PrimaryColumns()
|
||||
if len(primaryCols) == 1 {
|
||||
|
||||
@@ -1550,6 +1550,13 @@ func (manager *SGuestManager) ListItemExportKeys(ctx context.Context, q *sqlchem
|
||||
q.AppendField(eipsSubQuery.Field("ip_addr", "eip"))
|
||||
}
|
||||
|
||||
if utils.IsInStringArray("host", keys) {
|
||||
hostQuery := HostManager.Query("id", "name").GroupBy("id")
|
||||
hostSubQuery := hostQuery.SubQuery()
|
||||
q.LeftJoin(hostSubQuery, sqlchemy.Equals(q.Field("host_id"), hostSubQuery.Field("id")))
|
||||
q.AppendField(hostSubQuery.Field("name", "host"))
|
||||
}
|
||||
|
||||
// host_id as filter key
|
||||
if utils.IsInStringArray("region", keys) {
|
||||
zoneQuery := ZoneManager.Query("id", "cloudregion_id").SubQuery()
|
||||
@@ -1589,6 +1596,9 @@ func (manager *SGuestManager) GetExportExtraKeys(ctx context.Context, query json
|
||||
if disk, ok := rowMap["disk_size"]; ok {
|
||||
res.Set("disk", jsonutils.NewString(disk))
|
||||
}
|
||||
if host, ok := rowMap["host"]; ok && len(host) > 0 {
|
||||
res.Set("host", jsonutils.NewString(host))
|
||||
}
|
||||
if region, ok := rowMap["region"]; ok && len(region) > 0 {
|
||||
res.Set("region", jsonutils.NewString(region))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user