Skip to content
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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

01101sam
Copy link
Contributor

Fix: #1817
大概 3-5s 就能生成了
顺便修复下给文件大小为0的文件生成缩图导致上传后不生成

Copy link
Member

@HFO4 HFO4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the RP, I left some comments. Overall, it is not easy to implement under current generator interface.

}
}

if src == "" && file.Size > uint64(model.GetIntSetting("thumb_max_src_size", 31457280)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break max_src_size check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

('s on purpose as mentioned above)

@@ -117,11 +117,6 @@ 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)) {
Copy link
Member

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.

Copy link
Contributor Author

@01101sam 01101sam Aug 14, 2023

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

} else {
ffmpegFormats := strings.Split(model.GetSettingByName("thumb_ffmpeg_exts"), ",")
vipsFormats := strings.Split(model.GetSettingByName("thumb_vips_exts"), ",")
// 如果文件格式支持 ffmpeg 或 vips 生成缩略图,则使用源文件链接
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why include VIPS? src is not even used in VIPS generator.

Copy link
Contributor Author

@01101sam 01101sam Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for letting me know, didn't notice that when writiing this.
As documented of vips, url can also be used to generate thumbnail

Faked by ChatGPT, fuck

@@ -136,6 +131,24 @@ func (fs *FileSystem) generateThumbnail(ctx context.Context, file *model.File) e
src := ""
if conf.SystemConfig.Mode == "slave" || file.GetPolicy().Type == "local" {
src = file.SourceName
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seems to be a good abstraction:

  1. Generator specific logic should keeps in thumb package. This image.go should be generator-agnostic.

  2. src parameter in thumb generator is originally for file path. I understand in ffmpeg it happens can also be file URL, but it will make the interface definition inconsistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'll move it into thumb package, but this also means it needs sort of changing function sign too.

@WeidiDeng WeidiDeng changed the title feat: 加速缩图生成时间 feat: 加速缩略图生成时间 Aug 14, 2023
@01101sam 01101sam requested a review from HFO4 August 14, 2023 17:30
@01101sam 01101sam marked this pull request as draft August 14, 2023 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ffmpeg 生成缩略图忧化
2 participants