Backend: Clear folder cache after indexing #623

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer
2020-11-22 01:30:48 +01:00
parent 25e88bb1fc
commit cfa369cf17
4 changed files with 19 additions and 2 deletions

View File

@@ -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)
}
}
}

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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{