-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 加速缩略图生成时间 #1818
feat: 加速缩略图生成时间 #1818
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ import ( | |
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem/response" | ||
"github.com/cloudreve/Cloudreve/v3/pkg/thumb" | ||
"github.com/cloudreve/Cloudreve/v3/pkg/util" | ||
) | ||
) | ||
|
||
/* ================ | ||
图像处理相关 | ||
|
@@ -117,7 +117,20 @@ func (fs *FileSystem) generateThumbnail(ctx context.Context, file *model.File) e | |
defer cancel() | ||
// TODO: check file size | ||
|
||
if file.Size > uint64(model.GetIntSetting("thumb_max_src_size", 31457280)) { | ||
// Provide file source path for local policy files | ||
var err error | ||
url, src := "", "" | ||
if conf.SystemConfig.Mode == "slave" || file.GetPolicy().Type == "local" { | ||
src = file.SourceName | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not seems to be a good abstraction:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I'll move it into |
||
url, err = fs.Handler.Source(ctx, file.SourceName, 300, false, 0) | ||
if err != nil { | ||
util.Log().Warning("failed to get slave file download url: %w", err) | ||
} | ||
} | ||
|
||
// Only check max size for file that will touch local fs | ||
if url == "" && file.Size > uint64(model.GetIntSetting("thumb_max_src_size", 31457280)) { | ||
_ = updateThumbStatus(file, model.ThumbStatusNotAvailable) | ||
return errors.New("file too large") | ||
} | ||
|
@@ -128,17 +141,11 @@ func (fs *FileSystem) generateThumbnail(ctx context.Context, file *model.File) e | |
// 获取文件数据 | ||
source, err := fs.Handler.Get(newCtx, file.SourceName) | ||
if err != nil { | ||
return fmt.Errorf("faield to fetch original file %q: %w", file.SourceName, err) | ||
return fmt.Errorf("failed to fetch original file %q: %w", file.SourceName, err) | ||
} | ||
defer source.Close() | ||
|
||
// Provide file source path for local policy files | ||
src := "" | ||
if conf.SystemConfig.Mode == "slave" || file.GetPolicy().Type == "local" { | ||
src = file.SourceName | ||
} | ||
|
||
thumbRes, err := thumb.Generators.Generate(ctx, source, src, file.Name, model.GetSettingByNames( | ||
thumbRes, err := thumb.Generators.Generate(ctx, source, src, url, file, model.GetSettingByNames( | ||
"thumb_width", | ||
"thumb_height", | ||
"thumb_builtin_enabled", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unhappy path first - better to check max size before obtain workers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TLDR: I moved this code to below that local download checking, generating thumbnail shouldn't have a max size limit on.
So you want max size check to be the first priority?
Because by using url method size can be ignored and unlimited.
By letting size check for local (the code below) this could safely confirmes that we're not downloading huge files at local.
If this line puts in first this could break how this
generate by url
method goes.For example,
if I increase the max size to 10GB, (e.g. Some kind of movie)
when I failed to get the source file, the logic will fallbacks to local download mode
that's the place that the max size is worth for checking to avoid downloading huge files to local vm (As mentioned above)
In another way, if you check the max size first, this could cause lots of file that over the max size can't generate the thumbnail and forced ppl to increase in settings.
If they don't have big enough hard disk in local, this could cause OOM / full hard disk problem.
Update: I add that only checks for url, if not then it should be local file / file that will fetch to local.
For more, see
pipeline.go