mirror of
https://github.com/iyear/tdl
synced 2025-01-08 11:57:55 +08:00
fix(prj): set part size to max by default
* fix part size * remove useless --size flag in e2e test
This commit is contained in:
parent
98dac73585
commit
0a084ef513
@ -103,7 +103,6 @@ func Run(ctx context.Context, c *telegram.Client, kvd kv.KV, opts Options) (rerr
|
|||||||
|
|
||||||
options := downloader.Options{
|
options := downloader.Options{
|
||||||
Pool: pool,
|
Pool: pool,
|
||||||
PartSize: viper.GetInt(consts.FlagPartSize),
|
|
||||||
Threads: viper.GetInt(consts.FlagThreads),
|
Threads: viper.GetInt(consts.FlagThreads),
|
||||||
Iter: it,
|
Iter: it,
|
||||||
Progress: newProgress(dlProgress, it, opts),
|
Progress: newProgress(dlProgress, it, opts),
|
||||||
@ -114,7 +113,6 @@ func Run(ctx context.Context, c *telegram.Client, kvd kv.KV, opts Options) (rerr
|
|||||||
zap.String("dir", opts.Dir),
|
zap.String("dir", opts.Dir),
|
||||||
zap.Bool("rewrite_ext", opts.RewriteExt),
|
zap.Bool("rewrite_ext", opts.RewriteExt),
|
||||||
zap.Bool("skip_same", opts.SkipSame),
|
zap.Bool("skip_same", opts.SkipSame),
|
||||||
zap.Int("part_size", options.PartSize),
|
|
||||||
zap.Int("threads", options.Threads),
|
zap.Int("threads", options.Threads),
|
||||||
zap.Int("limit", limit))
|
zap.Int("limit", limit))
|
||||||
|
|
||||||
|
@ -98,7 +98,6 @@ func Run(ctx context.Context, c *telegram.Client, kvd kv.KV, opts Options) (rerr
|
|||||||
delay: viper.GetDuration(consts.FlagDelay),
|
delay: viper.GetDuration(consts.FlagDelay),
|
||||||
}),
|
}),
|
||||||
Progress: newProgress(fwProgress),
|
Progress: newProgress(fwProgress),
|
||||||
PartSize: viper.GetInt(consts.FlagPartSize),
|
|
||||||
Threads: viper.GetInt(consts.FlagThreads),
|
Threads: viper.GetInt(consts.FlagThreads),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -56,7 +56,6 @@ func Run(ctx context.Context, c *telegram.Client, kvd kv.KV, opts Options) (rerr
|
|||||||
|
|
||||||
options := uploader.Options{
|
options := uploader.Options{
|
||||||
Client: pool.Default(ctx),
|
Client: pool.Default(ctx),
|
||||||
PartSize: viper.GetInt(consts.FlagPartSize),
|
|
||||||
Threads: viper.GetInt(consts.FlagThreads),
|
Threads: viper.GetInt(consts.FlagThreads),
|
||||||
Iter: newIter(files, to, opts.Photo, opts.Remove, viper.GetDuration(consts.FlagDelay)),
|
Iter: newIter(files, to, opts.Photo, opts.Remove, viper.GetDuration(consts.FlagDelay)),
|
||||||
Progress: newProgress(upProgress),
|
Progress: newProgress(upProgress),
|
||||||
|
@ -156,6 +156,8 @@ func New() *cobra.Command {
|
|||||||
cmd.PersistentFlags().Bool(consts.FlagDebug, false, "enable debug mode")
|
cmd.PersistentFlags().Bool(consts.FlagDebug, false, "enable debug mode")
|
||||||
|
|
||||||
cmd.PersistentFlags().IntP(consts.FlagPartSize, "s", 512*1024, "part size for transfer")
|
cmd.PersistentFlags().IntP(consts.FlagPartSize, "s", 512*1024, "part size for transfer")
|
||||||
|
_ = cmd.PersistentFlags().MarkDeprecated(consts.FlagPartSize, "part size has been set to maximum by default, this flag will be removed in the future")
|
||||||
|
|
||||||
cmd.PersistentFlags().IntP(consts.FlagThreads, "t", 4, "max threads for transfer one item")
|
cmd.PersistentFlags().IntP(consts.FlagThreads, "t", 4, "max threads for transfer one item")
|
||||||
cmd.PersistentFlags().IntP(consts.FlagLimit, "l", 2, "max number of concurrent tasks")
|
cmd.PersistentFlags().IntP(consts.FlagLimit, "l", 2, "max number of concurrent tasks")
|
||||||
cmd.PersistentFlags().Int(consts.FlagPoolSize, 8, "specify the size of the DC pool, zero means infinity")
|
cmd.PersistentFlags().Int(consts.FlagPoolSize, 8, "specify the size of the DC pool, zero means infinity")
|
||||||
|
@ -13,13 +13,15 @@ import (
|
|||||||
"github.com/iyear/tdl/core/util/tutil"
|
"github.com/iyear/tdl/core/util/tutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// MaxPartSize refer to https://core.telegram.org/api/files#downloading-files
|
||||||
|
const MaxPartSize = 1024 * 1024
|
||||||
|
|
||||||
type Downloader struct {
|
type Downloader struct {
|
||||||
opts Options
|
opts Options
|
||||||
}
|
}
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Pool dcpool.Pool
|
Pool dcpool.Pool
|
||||||
PartSize int
|
|
||||||
Threads int
|
Threads int
|
||||||
Iter Iter
|
Iter Iter
|
||||||
Progress Progress
|
Progress Progress
|
||||||
@ -77,10 +79,10 @@ func (d *Downloader) download(ctx context.Context, elem Elem) error {
|
|||||||
client = d.opts.Pool.Takeout(ctx, elem.File().DC())
|
client = d.opts.Pool.Takeout(ctx, elem.File().DC())
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := downloader.NewDownloader().WithPartSize(d.opts.PartSize).
|
_, err := downloader.NewDownloader().WithPartSize(MaxPartSize).
|
||||||
Download(client, elem.File().Location()).
|
Download(client, elem.File().Location()).
|
||||||
WithThreads(tutil.BestThreads(elem.File().Size(), d.opts.Threads)).
|
WithThreads(tutil.BestThreads(elem.File().Size(), d.opts.Threads)).
|
||||||
Parallel(ctx, newWriteAt(elem, d.opts.Progress, d.opts.PartSize))
|
Parallel(ctx, newWriteAt(elem, d.opts.Progress, MaxPartSize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "download")
|
return errors.Wrap(err, "download")
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,9 @@ import (
|
|||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
"go.uber.org/multierr"
|
"go.uber.org/multierr"
|
||||||
|
|
||||||
|
tdownloader "github.com/iyear/tdl/core/downloader"
|
||||||
"github.com/iyear/tdl/core/tmedia"
|
"github.com/iyear/tdl/core/tmedia"
|
||||||
|
tuploader "github.com/iyear/tdl/core/uploader"
|
||||||
"github.com/iyear/tdl/core/util/tutil"
|
"github.com/iyear/tdl/core/util/tutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -47,7 +49,7 @@ func (f *Forwarder) cloneMedia(ctx context.Context, opts cloneOptions, dryRun bo
|
|||||||
threads := tutil.BestThreads(opts.media.Size, f.opts.Threads)
|
threads := tutil.BestThreads(opts.media.Size, f.opts.Threads)
|
||||||
|
|
||||||
_, err = downloader.NewDownloader().
|
_, err = downloader.NewDownloader().
|
||||||
WithPartSize(f.opts.PartSize).
|
WithPartSize(tdownloader.MaxPartSize).
|
||||||
Download(f.opts.Pool.Client(ctx, opts.media.DC), opts.media.InputFileLoc).
|
Download(f.opts.Pool.Client(ctx, opts.media.DC), opts.media.InputFileLoc).
|
||||||
WithThreads(threads).
|
WithThreads(threads).
|
||||||
Parallel(ctx, writeAt{
|
Parallel(ctx, writeAt{
|
||||||
@ -66,7 +68,7 @@ func (f *Forwarder) cloneMedia(ctx context.Context, opts cloneOptions, dryRun bo
|
|||||||
|
|
||||||
upload := uploader.NewUpload(opts.media.Name, temp, opts.media.Size)
|
upload := uploader.NewUpload(opts.media.Name, temp, opts.media.Size)
|
||||||
file, err = uploader.NewUploader(f.opts.Pool.Default(ctx)).
|
file, err = uploader.NewUploader(f.opts.Pool.Default(ctx)).
|
||||||
WithPartSize(f.opts.PartSize).
|
WithPartSize(tuploader.MaxPartSize).
|
||||||
WithThreads(threads).
|
WithThreads(threads).
|
||||||
WithProgress(uploaded{
|
WithProgress(uploaded{
|
||||||
opts: opts,
|
opts: opts,
|
||||||
|
@ -26,7 +26,6 @@ type Mode int
|
|||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Pool dcpool.Pool
|
Pool dcpool.Pool
|
||||||
PartSize int
|
|
||||||
Threads int
|
Threads int
|
||||||
Iter Iter
|
Iter Iter
|
||||||
Progress Progress
|
Progress Progress
|
||||||
|
@ -17,13 +17,15 @@ import (
|
|||||||
"github.com/iyear/tdl/core/util/mediautil"
|
"github.com/iyear/tdl/core/util/mediautil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// MaxPartSize refer to https://core.telegram.org/api/files#uploading-files
|
||||||
|
const MaxPartSize = 512 * 1024
|
||||||
|
|
||||||
type Uploader struct {
|
type Uploader struct {
|
||||||
opts Options
|
opts Options
|
||||||
}
|
}
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Client *tg.Client
|
Client *tg.Client
|
||||||
PartSize int
|
|
||||||
Threads int
|
Threads int
|
||||||
Iter Iter
|
Iter Iter
|
||||||
Progress Progress
|
Progress Progress
|
||||||
@ -72,7 +74,7 @@ func (u *Uploader) upload(ctx context.Context, elem Elem) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
up := uploader.NewUploader(u.opts.Client).
|
up := uploader.NewUploader(u.opts.Client).
|
||||||
WithPartSize(u.opts.PartSize).
|
WithPartSize(MaxPartSize).
|
||||||
WithThreads(u.opts.Threads).
|
WithThreads(u.opts.Threads).
|
||||||
WithProgress(&wrapProcess{
|
WithProgress(&wrapProcess{
|
||||||
elem: elem,
|
elem: elem,
|
||||||
|
@ -5,7 +5,7 @@ const (
|
|||||||
FlagProxy = "proxy"
|
FlagProxy = "proxy"
|
||||||
FlagNamespace = "ns"
|
FlagNamespace = "ns"
|
||||||
FlagDebug = "debug"
|
FlagDebug = "debug"
|
||||||
FlagPartSize = "size"
|
FlagPartSize = "size" // Deprecated: all part size should be set to maximum by default
|
||||||
FlagThreads = "threads"
|
FlagThreads = "threads"
|
||||||
FlagLimit = "limit"
|
FlagLimit = "limit"
|
||||||
FlagPoolSize = "pool"
|
FlagPoolSize = "pool"
|
||||||
|
@ -53,7 +53,6 @@ func exec(cmd *cobra.Command, args []string, success bool) {
|
|||||||
|
|
||||||
log.Printf("args: %s\n", args)
|
log.Printf("args: %s\n", args)
|
||||||
cmd.SetArgs(append([]string{
|
cmd.SetArgs(append([]string{
|
||||||
"-s", "131072", // self-hosted Telegram server don't support 1MiB
|
|
||||||
"-n", testAccount,
|
"-n", testAccount,
|
||||||
"--storage", fmt.Sprintf("type=file,path=%s", sessionFile),
|
"--storage", fmt.Sprintf("type=file,path=%s", sessionFile),
|
||||||
}, args...))
|
}, args...))
|
||||||
|
Loading…
Reference in New Issue
Block a user