forked from TrueCloudLab/rclone
lsjson: add --no-mimetype flag, speed up lsf
Before this changed we unconditionally fetched the MimeType. On Some backends like s3 and swift this takes an extra transaction which meant that `lsf` on those backends was needlessly slow. This adds an internal option so `lsf` can declare whether it wants MimeTypes or not depending on whether the user asked for them and an external flag `--no-mimetype` for `lsjson`. See: https://forum.rclone.org/t/reliably-setup-incremental-updates/14006/8
This commit is contained in:
parent
9c9cdf1712
commit
bfd9f32188
3 changed files with 17 additions and 9 deletions
|
@ -167,6 +167,7 @@ func Lsf(ctx context.Context, fsrc fs.Fs, out io.Writer) error {
|
||||||
list.SetAbsolute(absolute)
|
list.SetAbsolute(absolute)
|
||||||
var opt = operations.ListJSONOpt{
|
var opt = operations.ListJSONOpt{
|
||||||
NoModTime: true,
|
NoModTime: true,
|
||||||
|
NoMimeType: true,
|
||||||
DirsOnly: dirsOnly,
|
DirsOnly: dirsOnly,
|
||||||
FilesOnly: filesOnly,
|
FilesOnly: filesOnly,
|
||||||
Recurse: recurse,
|
Recurse: recurse,
|
||||||
|
@ -188,6 +189,7 @@ func Lsf(ctx context.Context, fsrc fs.Fs, out io.Writer) error {
|
||||||
list.AddID()
|
list.AddID()
|
||||||
case 'm':
|
case 'm':
|
||||||
list.AddMimeType()
|
list.AddMimeType()
|
||||||
|
opt.NoMimeType = false
|
||||||
case 'e':
|
case 'e':
|
||||||
list.AddEncrypted()
|
list.AddEncrypted()
|
||||||
opt.ShowEncrypted = true
|
opt.ShowEncrypted = true
|
||||||
|
|
|
@ -24,6 +24,7 @@ func init() {
|
||||||
flags.BoolVarP(cmdFlags, &opt.Recurse, "recursive", "R", false, "Recurse into the listing.")
|
flags.BoolVarP(cmdFlags, &opt.Recurse, "recursive", "R", false, "Recurse into the listing.")
|
||||||
flags.BoolVarP(cmdFlags, &opt.ShowHash, "hash", "", false, "Include hashes in the output (may take longer).")
|
flags.BoolVarP(cmdFlags, &opt.ShowHash, "hash", "", false, "Include hashes in the output (may take longer).")
|
||||||
flags.BoolVarP(cmdFlags, &opt.NoModTime, "no-modtime", "", false, "Don't read the modification time (can speed things up).")
|
flags.BoolVarP(cmdFlags, &opt.NoModTime, "no-modtime", "", false, "Don't read the modification time (can speed things up).")
|
||||||
|
flags.BoolVarP(cmdFlags, &opt.NoMimeType, "no-mimetype", "", false, "Don't read the mime type (can speed things up).")
|
||||||
flags.BoolVarP(cmdFlags, &opt.ShowEncrypted, "encrypted", "M", false, "Show the encrypted names.")
|
flags.BoolVarP(cmdFlags, &opt.ShowEncrypted, "encrypted", "M", false, "Show the encrypted names.")
|
||||||
flags.BoolVarP(cmdFlags, &opt.ShowOrigIDs, "original", "", false, "Show the ID of the underlying Object.")
|
flags.BoolVarP(cmdFlags, &opt.ShowOrigIDs, "original", "", false, "Show the ID of the underlying Object.")
|
||||||
flags.BoolVarP(cmdFlags, &opt.FilesOnly, "files-only", "", false, "Show only files in the listing.")
|
flags.BoolVarP(cmdFlags, &opt.FilesOnly, "files-only", "", false, "Show only files in the listing.")
|
||||||
|
@ -59,7 +60,9 @@ The output is an array of Items, where each Item looks like this
|
||||||
|
|
||||||
If --hash is not specified the Hashes property won't be emitted.
|
If --hash is not specified the Hashes property won't be emitted.
|
||||||
|
|
||||||
If --no-modtime is specified then ModTime will be blank.
|
If --no-modtime is specified then ModTime will be blank. This can speed things up on remotes where reading the ModTime takes an extra request (eg s3, swift).
|
||||||
|
|
||||||
|
If --no-mimetype is specified then MimeType will be blank. This can speed things up on remotes where reading the MimeType takes an extra request (eg s3, swift).
|
||||||
|
|
||||||
If --encrypted is not specified the Encrypted won't be emitted.
|
If --encrypted is not specified the Encrypted won't be emitted.
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@ func formatForPrecision(precision time.Duration) string {
|
||||||
type ListJSONOpt struct {
|
type ListJSONOpt struct {
|
||||||
Recurse bool `json:"recurse"`
|
Recurse bool `json:"recurse"`
|
||||||
NoModTime bool `json:"noModTime"`
|
NoModTime bool `json:"noModTime"`
|
||||||
|
NoMimeType bool `json:"noMimeType"`
|
||||||
ShowEncrypted bool `json:"showEncrypted"`
|
ShowEncrypted bool `json:"showEncrypted"`
|
||||||
ShowOrigIDs bool `json:"showOrigIDs"`
|
ShowOrigIDs bool `json:"showOrigIDs"`
|
||||||
ShowHash bool `json:"showHash"`
|
ShowHash bool `json:"showHash"`
|
||||||
|
@ -117,11 +118,13 @@ func ListJSON(ctx context.Context, fsrc fs.Fs, remote string, opt *ListJSONOpt,
|
||||||
Path: entry.Remote(),
|
Path: entry.Remote(),
|
||||||
Name: path.Base(entry.Remote()),
|
Name: path.Base(entry.Remote()),
|
||||||
Size: entry.Size(),
|
Size: entry.Size(),
|
||||||
MimeType: fs.MimeTypeDirEntry(ctx, entry),
|
|
||||||
}
|
}
|
||||||
if !opt.NoModTime {
|
if !opt.NoModTime {
|
||||||
item.ModTime = Timestamp{When: entry.ModTime(ctx), Format: format}
|
item.ModTime = Timestamp{When: entry.ModTime(ctx), Format: format}
|
||||||
}
|
}
|
||||||
|
if !opt.NoMimeType {
|
||||||
|
item.MimeType = fs.MimeTypeDirEntry(ctx, entry)
|
||||||
|
}
|
||||||
if cipher != nil {
|
if cipher != nil {
|
||||||
switch entry.(type) {
|
switch entry.(type) {
|
||||||
case fs.Directory:
|
case fs.Directory:
|
||||||
|
|
Loading…
Add table
Reference in a new issue