From 8fd991a5a618e4dd0086669d682ead22d99a3a6e Mon Sep 17 00:00:00 2001 From: RanXom Date: Mon, 13 Jul 2026 13:05:50 +0530 Subject: feat(thumbnail): define thumbnail cache layout --- internal/thumbnail/cache.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 internal/thumbnail/cache.go (limited to 'internal/thumbnail/cache.go') diff --git a/internal/thumbnail/cache.go b/internal/thumbnail/cache.go new file mode 100644 index 0000000..38f5d07 --- /dev/null +++ b/internal/thumbnail/cache.go @@ -0,0 +1,28 @@ +package thumbnail + +import ( + "path/filepath" + + "github.com/RanXom/galleryd/internal/gallery" +) + +const ( + thumbnailExtension = ".webp" +) + +// cachePath returns the on-disk cache location for a photo thumbnail. +// +// Thumbnails are sharded by the first two characters of the photo ID to +// avoid placing large numbers of files in a single directory. +func (g *Generator) cachePath(photo gallery.Photo) string { + shard := photo.ID[:2] + + filename := photo.ID + thumbnailExtension + + return filepath.Join( + g.cacheDir, + "thumbs", + shard, + filename, + ) +} -- cgit v1.2.3 From 546751bda402887fe31f09768e29d1cf5f531f83 Mon Sep 17 00:00:00 2001 From: RanXom Date: Mon, 13 Jul 2026 14:02:57 +0530 Subject: refactor(thumbnail): version thumbnail cache layout --- internal/thumbnail/cache.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'internal/thumbnail/cache.go') diff --git a/internal/thumbnail/cache.go b/internal/thumbnail/cache.go index 38f5d07..80164e9 100644 --- a/internal/thumbnail/cache.go +++ b/internal/thumbnail/cache.go @@ -7,6 +7,7 @@ import ( ) const ( + thumbnailVersion = "v1" thumbnailExtension = ".webp" ) @@ -22,6 +23,7 @@ func (g *Generator) cachePath(photo gallery.Photo) string { return filepath.Join( g.cacheDir, "thumbs", + thumbnailVersion, shard, filename, ) -- cgit v1.2.3 From e48a9f9dafefef4844c49d417af8d13978455247 Mon Sep 17 00:00:00 2001 From: RanXom Date: Mon, 13 Jul 2026 14:11:53 +0530 Subject: feat(thumbnail): initialize thumbnail cache --- internal/thumbnail/cache.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'internal/thumbnail/cache.go') diff --git a/internal/thumbnail/cache.go b/internal/thumbnail/cache.go index 80164e9..740268a 100644 --- a/internal/thumbnail/cache.go +++ b/internal/thumbnail/cache.go @@ -1,16 +1,21 @@ package thumbnail import ( + "fmt" "path/filepath" "github.com/RanXom/galleryd/internal/gallery" ) const ( - thumbnailVersion = "v1" - thumbnailExtension = ".webp" + thumbnailCacheVersion = 1 + thumbnailExtension = ".webp" ) +func cacheVersion() string { + return fmt.Sprintf("v%d", thumbnailCacheVersion) +} + // cachePath returns the on-disk cache location for a photo thumbnail. // // Thumbnails are sharded by the first two characters of the photo ID to @@ -23,7 +28,7 @@ func (g *Generator) cachePath(photo gallery.Photo) string { return filepath.Join( g.cacheDir, "thumbs", - thumbnailVersion, + cacheVersion(), shard, filename, ) -- cgit v1.2.3