Storage: optimize sql list operation (#53009)

This commit is contained in:
Artur Wierzbicki 2022-07-30 00:19:28 +04:00 committed by GitHub
parent 08dabfaffc
commit 046a2602ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,6 +33,11 @@ type file struct {
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 {
PathHash string `xorm:"path_hash"`
Key string `xorm:"key"`
@ -339,6 +344,12 @@ func (s dbFileStorage) List(ctx context.Context, folderPath string, paging *Pagi
sess.Where("path > ?", cursor)
}
if options.WithContents {
sess.Cols(allFileCols...)
} else {
sess.Cols(fileColsNoContents...)
}
if err := sess.Find(&foundFiles); err != nil {
return err
}