mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-09-19 12:16:24 +08:00
perf(ftp): improve concurrent Link response; fix alias/local driver issues (#974)
This commit is contained in:
@ -2,6 +2,7 @@ package op
|
||||
|
||||
import (
|
||||
"context"
|
||||
stderrors "errors"
|
||||
stdpath "path"
|
||||
"slices"
|
||||
"strings"
|
||||
@ -250,6 +251,7 @@ func GetUnwrap(ctx context.Context, storage driver.Driver, path string) (model.O
|
||||
|
||||
var linkCache = cache.NewMemCache(cache.WithShards[*model.Link](16))
|
||||
var linkG = singleflight.Group[*model.Link]{Remember: true}
|
||||
var errLinkMFileCache = stderrors.New("ErrLinkMFileCache")
|
||||
|
||||
// Link get link, if is an url. should have an expiry time
|
||||
func Link(ctx context.Context, storage driver.Driver, path string, args model.LinkArgs) (*model.Link, model.Obj, error) {
|
||||
@ -292,11 +294,16 @@ func Link(ctx context.Context, storage driver.Driver, path string, args model.Li
|
||||
}
|
||||
|
||||
var forget any
|
||||
var linkM *model.Link
|
||||
fn := func() (*model.Link, error) {
|
||||
link, err := storage.Link(ctx, file, args)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed get link")
|
||||
}
|
||||
if link.MFile != nil && forget != nil {
|
||||
linkM = link
|
||||
return nil, errLinkMFileCache
|
||||
}
|
||||
if link.Expiration != nil {
|
||||
linkCache.Set(key, link, cache.WithEx[*model.Link](*link.Expiration))
|
||||
}
|
||||
@ -326,11 +333,19 @@ func Link(ctx context.Context, storage driver.Driver, path string, args model.Li
|
||||
link.AcquireReference()
|
||||
}
|
||||
}
|
||||
|
||||
if err == errLinkMFileCache {
|
||||
if linkM != nil {
|
||||
return linkM, file, nil
|
||||
}
|
||||
forget = nil
|
||||
link, err = fn()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return link, file, err
|
||||
return link, file, nil
|
||||
}
|
||||
|
||||
// Other api
|
||||
|
Reference in New Issue
Block a user