feat: use real image path to calculate cache key
parent
cf85404dd2
commit
c1987237d0
|
@ -185,6 +185,19 @@ func (i *FileInfo) Checksum(algo string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (i *FileInfo) RealPath() string {
|
||||
if realPathFs, ok := i.Fs.(interface {
|
||||
RealPath(name string) (fPath string, err error)
|
||||
}); ok {
|
||||
realPath, err := realPathFs.RealPath(i.Path)
|
||||
if err == nil {
|
||||
return realPath
|
||||
}
|
||||
}
|
||||
|
||||
return i.Path
|
||||
}
|
||||
|
||||
//nolint:goconst
|
||||
//TODO: use constants
|
||||
func (i *FileInfo) detectType(modify, saveContent, readHeader bool) error {
|
||||
|
|
|
@ -91,7 +91,7 @@ func handleImagePreview(
|
|||
return errToStatus(err), err
|
||||
}
|
||||
|
||||
cacheKey := previewCacheKey(file.Path, file.ModTime.Unix(), previewSize)
|
||||
cacheKey := previewCacheKey(file, previewSize)
|
||||
resizedImage, ok, err := fileCache.Load(r.Context(), cacheKey)
|
||||
if err != nil {
|
||||
return errToStatus(err), err
|
||||
|
@ -142,7 +142,7 @@ func createPreview(imgSvc ImgService, fileCache FileCache,
|
|||
}
|
||||
|
||||
go func() {
|
||||
cacheKey := previewCacheKey(file.Path, file.ModTime.Unix(), previewSize)
|
||||
cacheKey := previewCacheKey(file, previewSize)
|
||||
if err := fileCache.Store(context.Background(), cacheKey, buf.Bytes()); err != nil {
|
||||
fmt.Printf("failed to cache resized image: %v", err)
|
||||
}
|
||||
|
@ -151,6 +151,6 @@ func createPreview(imgSvc ImgService, fileCache FileCache,
|
|||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func previewCacheKey(fPath string, fTime int64, previewSize PreviewSize) string {
|
||||
return fmt.Sprintf("%x%x%x", fPath, fTime, previewSize)
|
||||
func previewCacheKey(f *files.FileInfo, previewSize PreviewSize) string {
|
||||
return fmt.Sprintf("%x%x%x", f.RealPath(), f.ModTime.Unix(), previewSize)
|
||||
}
|
||||
|
|
|
@ -283,7 +283,7 @@ func writeFile(fs afero.Fs, dst string, in io.Reader) (os.FileInfo, error) {
|
|||
func delThumbs(ctx context.Context, fileCache FileCache, file *files.FileInfo) error {
|
||||
for _, previewSizeName := range PreviewSizeNames() {
|
||||
size, _ := ParsePreviewSize(previewSizeName)
|
||||
if err := fileCache.Delete(ctx, previewCacheKey(file.Path, file.ModTime.Unix(), size)); err != nil {
|
||||
if err := fileCache.Delete(ctx, previewCacheKey(file, size)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue