Storage: optimize sql list operation (#53009)
This commit is contained in:
@@ -33,6 +33,11 @@ type file struct {
|
|||||||
MimeType string `xorm:"mime_type"`
|
MimeType string `xorm:"mime_type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
fileColsNoContents = []string{"path", "path_hash", "parent_folder_path_hash", "etag", "cache_control", "content_disposition", "updated", "created", "size", "mime_type"}
|
||||||
|
allFileCols = append([]string{"contents"}, fileColsNoContents...)
|
||||||
|
)
|
||||||
|
|
||||||
type fileMeta struct {
|
type fileMeta struct {
|
||||||
PathHash string `xorm:"path_hash"`
|
PathHash string `xorm:"path_hash"`
|
||||||
Key string `xorm:"key"`
|
Key string `xorm:"key"`
|
||||||
@@ -339,6 +344,12 @@ func (s dbFileStorage) List(ctx context.Context, folderPath string, paging *Pagi
|
|||||||
sess.Where("path > ?", cursor)
|
sess.Where("path > ?", cursor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.WithContents {
|
||||||
|
sess.Cols(allFileCols...)
|
||||||
|
} else {
|
||||||
|
sess.Cols(fileColsNoContents...)
|
||||||
|
}
|
||||||
|
|
||||||
if err := sess.Find(&foundFiles); err != nil {
|
if err := sess.Find(&foundFiles); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user