mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Backend: Clear folder cache after indexing #623
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
@@ -33,7 +33,7 @@ func ClearAlbumThumbCache(uid string) {
|
||||
cacheKey := fmt.Sprintf("album-thumbs:%s:%s", uid, typeName)
|
||||
|
||||
if err := cache.Delete(cacheKey); err == nil {
|
||||
log.Debugf("album: removed %s from cache", cacheKey)
|
||||
log.Debugf("removed %s from cache", cacheKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,17 @@ type FoldersResponse struct {
|
||||
Cached bool `json:"cached,omitempty"`
|
||||
}
|
||||
|
||||
// ClearFoldersCache removes folder lists from cache e.g. after indexing.
|
||||
func ClearFoldersCache(rootName string) {
|
||||
cache := service.Cache()
|
||||
|
||||
cacheKey := fmt.Sprintf("folders:%s:%t:%t", rootName, true, false)
|
||||
|
||||
if err := cache.Delete(cacheKey); err == nil {
|
||||
log.Debugf("removed %s from cache", cacheKey)
|
||||
}
|
||||
}
|
||||
|
||||
// GetFolders is a reusable request handler for directory listings (GET /api/v1/folders/*).
|
||||
func GetFolders(router *gin.RouterGroup, urlPath, rootName, rootPath string) {
|
||||
handler := func(c *gin.Context) {
|
||||
@@ -52,7 +63,7 @@ func GetFolders(router *gin.RouterGroup, urlPath, rootName, rootPath string) {
|
||||
resp := FoldersResponse{Root: rootName, Recursive: recursive, Cached: !uncached}
|
||||
path := c.Param("path")
|
||||
|
||||
cacheKey := fmt.Sprintf("folders:%s:%t:%t", filepath.Join(rootPath, path), recursive, listFiles)
|
||||
cacheKey := fmt.Sprintf("folders:%s:%t:%t", filepath.Join(rootName, path), recursive, listFiles)
|
||||
|
||||
if !uncached {
|
||||
if cacheData, err := cache.Get(cacheKey); err == nil {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/photoprism/photoprism/internal/acl"
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/form"
|
||||
"github.com/photoprism/photoprism/internal/i18n"
|
||||
@@ -59,6 +60,8 @@ func StartImport(router *gin.RouterGroup) {
|
||||
|
||||
imp := service.Import()
|
||||
|
||||
ClearFoldersCache(entity.RootImport)
|
||||
|
||||
var opt photoprism.ImportOptions
|
||||
|
||||
if f.Move {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/photoprism/photoprism/internal/acl"
|
||||
"github.com/photoprism/photoprism/internal/entity"
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/form"
|
||||
"github.com/photoprism/photoprism/internal/i18n"
|
||||
@@ -59,6 +60,8 @@ func StartIndexing(router *gin.RouterGroup) {
|
||||
|
||||
indexed := ind.Start(indOpt)
|
||||
|
||||
ClearFoldersCache(entity.RootOriginals)
|
||||
|
||||
prg := service.Purge()
|
||||
|
||||
prgOpt := photoprism.PurgeOptions{
|
||||
|
||||
Reference in New Issue
Block a user