From d9cff24c752e7ba0eb9387cf7a4f69d6907a5d13 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Wed, 3 Mar 2021 14:10:08 +0800 Subject: [PATCH 1/3] Modify: disable association_autoupdate in model.File.UpdateSourceName --- models/file.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/file.go b/models/file.go index bc2f0114..7b1d6e8f 100644 --- a/models/file.go +++ b/models/file.go @@ -196,7 +196,7 @@ func (file *File) UpdateSize(value uint64) error { // UpdateSourceName 更新文件的源文件名 func (file *File) UpdateSourceName(value string) error { - return DB.Model(&file).Update("source_name", value).Error + return DB.Model(&file).Set("gorm:association_autoupdate", false).Update("source_name", value).Error } /* From a93b964d8befce9176a7a9dde21b524599aafcd9 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Wed, 3 Mar 2021 17:07:26 +0800 Subject: [PATCH 2/3] Modify: OneDrive file URL cache will refreshed after file is updated --- pkg/filesystem/driver/onedrive/handler.go | 9 +++++++-- pkg/filesystem/driver/onedrive/handler_test.go | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pkg/filesystem/driver/onedrive/handler.go b/pkg/filesystem/driver/onedrive/handler.go index 2bedb166..c1e8717a 100644 --- a/pkg/filesystem/driver/onedrive/handler.go +++ b/pkg/filesystem/driver/onedrive/handler.go @@ -152,8 +152,13 @@ func (handler Driver) Source( isDownload bool, speed int, ) (string, error) { + cacheKey := fmt.Sprintf("onedrive_source_%d_%s", handler.Policy.ID, path) + if file, ok := ctx.Value(fsctx.FileModelCtx).(model.File); ok { + cacheKey = fmt.Sprintf("onedrive_source_file_%d_%d", file.UpdatedAt.Unix(), file.ID) + } + // 尝试从缓存中查找 - if cachedURL, ok := cache.Get(fmt.Sprintf("onedrive_source_%d_%s", handler.Policy.ID, path)); ok { + if cachedURL, ok := cache.Get(cacheKey); ok { return handler.replaceSourceHost(cachedURL.(string)) } @@ -162,7 +167,7 @@ func (handler Driver) Source( if err == nil { // 写入新的缓存 cache.Set( - fmt.Sprintf("onedrive_source_%d_%s", handler.Policy.ID, path), + cacheKey, res.DownloadURL, model.GetIntSetting("onedrive_source_timeout", 1800), ) diff --git a/pkg/filesystem/driver/onedrive/handler_test.go b/pkg/filesystem/driver/onedrive/handler_test.go index a4a5be14..4f0bb977 100644 --- a/pkg/filesystem/driver/onedrive/handler_test.go +++ b/pkg/filesystem/driver/onedrive/handler_test.go @@ -2,6 +2,7 @@ package onedrive import ( "context" + "fmt" "io" "io/ioutil" "net/http" @@ -150,6 +151,21 @@ func TestDriver_Source(t *testing.T) { asserts.Equal("res", res) } + // 命中缓存 上下文存在文件 成功 + { + file := model.File{} + file.ID = 1 + file.UpdatedAt = time.Now() + ctx := context.WithValue(context.Background(), fsctx.FileModelCtx, file) + handler.Client.Credential.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix() + handler.Client.Credential.AccessToken = "1" + cache.Set(fmt.Sprintf("onedrive_source_file_%d_1", file.UpdatedAt.Unix()), "res", 0) + res, err := handler.Source(ctx, "123.jpg", url.URL{}, 0, true, 0) + cache.Deletes([]string{"0_123.jpg"}, "onedrive_source_") + asserts.NoError(err) + asserts.Equal("res", res) + } + // 成功 { handler.Client.Credential.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix() From e44ec0e6bf6da2e11bcc6e327df95398c475e0f6 Mon Sep 17 00:00:00 2001 From: AaronLiu Date: Fri, 5 Mar 2021 15:44:33 +0800 Subject: [PATCH 3/3] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 38 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..dd84ea78 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..bbcbbe7d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here.