fix(prj): set part size to max by default

* fix part size

* remove useless --size flag in e2e test
This commit is contained in:
Junyu Liu 2024-11-07 18:14:38 +08:00 committed by GitHub
parent 98dac73585
commit 0a084ef513
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 16 additions and 14 deletions

View File

@ -103,7 +103,6 @@ func Run(ctx context.Context, c *telegram.Client, kvd kv.KV, opts Options) (rerr
options := downloader.Options{
Pool: pool,
PartSize: viper.GetInt(consts.FlagPartSize),
Threads: viper.GetInt(consts.FlagThreads),
Iter: it,
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.Bool("rewrite_ext", opts.RewriteExt),
zap.Bool("skip_same", opts.SkipSame),
zap.Int("part_size", options.PartSize),
zap.Int("threads", options.Threads),
zap.Int("limit", limit))

View File

@ -98,7 +98,6 @@ func Run(ctx context.Context, c *telegram.Client, kvd kv.KV, opts Options) (rerr
delay: viper.GetDuration(consts.FlagDelay),
}),
Progress: newProgress(fwProgress),
PartSize: viper.GetInt(consts.FlagPartSize),
Threads: viper.GetInt(consts.FlagThreads),
})

View File

@ -56,7 +56,6 @@ func Run(ctx context.Context, c *telegram.Client, kvd kv.KV, opts Options) (rerr
options := uploader.Options{
Client: pool.Default(ctx),
PartSize: viper.GetInt(consts.FlagPartSize),
Threads: viper.GetInt(consts.FlagThreads),
Iter: newIter(files, to, opts.Photo, opts.Remove, viper.GetDuration(consts.FlagDelay)),
Progress: newProgress(upProgress),

View File

@ -156,6 +156,8 @@ func New() *cobra.Command {
cmd.PersistentFlags().Bool(consts.FlagDebug, false, "enable debug mode")
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.FlagLimit, "l", 2, "max number of concurrent tasks")
cmd.PersistentFlags().Int(consts.FlagPoolSize, 8, "specify the size of the DC pool, zero means infinity")

View File

@ -13,13 +13,15 @@ import (
"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 {
opts Options
}
type Options struct {
Pool dcpool.Pool
PartSize int
Threads int
Iter Iter
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())
}
_, err := downloader.NewDownloader().WithPartSize(d.opts.PartSize).
_, err := downloader.NewDownloader().WithPartSize(MaxPartSize).
Download(client, elem.File().Location()).
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 {
return errors.Wrap(err, "download")
}

View File

@ -12,7 +12,9 @@ import (
"go.uber.org/atomic"
"go.uber.org/multierr"
tdownloader "github.com/iyear/tdl/core/downloader"
"github.com/iyear/tdl/core/tmedia"
tuploader "github.com/iyear/tdl/core/uploader"
"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)
_, err = downloader.NewDownloader().
WithPartSize(f.opts.PartSize).
WithPartSize(tdownloader.MaxPartSize).
Download(f.opts.Pool.Client(ctx, opts.media.DC), opts.media.InputFileLoc).
WithThreads(threads).
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)
file, err = uploader.NewUploader(f.opts.Pool.Default(ctx)).
WithPartSize(f.opts.PartSize).
WithPartSize(tuploader.MaxPartSize).
WithThreads(threads).
WithProgress(uploaded{
opts: opts,

View File

@ -26,7 +26,6 @@ type Mode int
type Options struct {
Pool dcpool.Pool
PartSize int
Threads int
Iter Iter
Progress Progress

View File

@ -17,13 +17,15 @@ import (
"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 {
opts Options
}
type Options struct {
Client *tg.Client
PartSize int
Threads int
Iter Iter
Progress Progress
@ -72,7 +74,7 @@ func (u *Uploader) upload(ctx context.Context, elem Elem) error {
}
up := uploader.NewUploader(u.opts.Client).
WithPartSize(u.opts.PartSize).
WithPartSize(MaxPartSize).
WithThreads(u.opts.Threads).
WithProgress(&wrapProcess{
elem: elem,

View File

@ -5,7 +5,7 @@ const (
FlagProxy = "proxy"
FlagNamespace = "ns"
FlagDebug = "debug"
FlagPartSize = "size"
FlagPartSize = "size" // Deprecated: all part size should be set to maximum by default
FlagThreads = "threads"
FlagLimit = "limit"
FlagPoolSize = "pool"

View File

@ -53,7 +53,6 @@ func exec(cmd *cobra.Command, args []string, success bool) {
log.Printf("args: %s\n", args)
cmd.SetArgs(append([]string{
"-s", "131072", // self-hosted Telegram server don't support 1MiB
"-n", testAccount,
"--storage", fmt.Sprintf("type=file,path=%s", sessionFile),
}, args...))