Backend: Remove allegro/bigcache in favor of patrickmn/go-cache #807
This commit is contained in:
parent
54e2ca3dab
commit
6811a07e8a
19 changed files with 96 additions and 164 deletions
5
NOTICE
5
NOTICE
|
@ -513,9 +513,6 @@ Revision ID: 4dceb74574f814ada169d193dc24e657d99b7a66
|
|||
better-assert 1.0.2 - MIT
|
||||
bfj 6.1.2 - MIT
|
||||
big.js 5.2.2 - MIT
|
||||
bigcache 21e5ca5c3d539f9 - Apache-2.0
|
||||
4e8dc563350acd9
|
||||
7c5400154f
|
||||
binary- 2.0.0 - MIT
|
||||
extensions
|
||||
bindings 1.5.0 - MIT
|
||||
|
@ -21531,7 +21528,7 @@ SOFTWARE.
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
Apache-2.0
|
||||
Found in bigcache (bbb395e1b5a40435c5b93bf7efbc9c8841a01020), detect-libc (1.0.3), yaml.v2 (0b1645d91e851e735d3e23330303ce81f70adbe3)
|
||||
Found in detect-libc (1.0.3), yaml.v2 (0b1645d91e851e735d3e23330303ce81f70adbe3)
|
||||
|
||||
|
||||
Apache License
|
||||
|
|
3
go.mod
3
go.mod
|
@ -1,7 +1,6 @@
|
|||
module github.com/photoprism/photoprism
|
||||
|
||||
require (
|
||||
github.com/allegro/bigcache v1.2.1
|
||||
github.com/araddon/dateparse v0.0.0-20201001162425-8aadafed4dc4
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
|
@ -19,7 +18,7 @@ require (
|
|||
github.com/dustin/go-humanize v1.0.0
|
||||
github.com/gin-gonic/gin v1.6.3
|
||||
github.com/go-playground/validator/v10 v10.3.0 // indirect
|
||||
github.com/golang/geo v0.0.0-20200730024412-e86565bf3f35
|
||||
github.com/golang/geo v0.0.0-20210108004804-a63082ebfb66
|
||||
github.com/golang/protobuf v1.4.2 // indirect
|
||||
github.com/google/open-location-code/go v0.0.0-20201229230907-d47d9f9b95e9
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
|
|
32
go.sum
32
go.sum
|
@ -19,8 +19,6 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
|
|||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
||||
github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKSc=
|
||||
github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
|
||||
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
|
||||
github.com/araddon/dateparse v0.0.0-20201001162425-8aadafed4dc4 h1:OkS1BqB3CzLtGRznRyvriSY8jeaVk2CrDn2ZiRQgMUI=
|
||||
github.com/araddon/dateparse v0.0.0-20201001162425-8aadafed4dc4/go.mod h1:hMAUZFIkk4B1FouGxqlogyMyU6BwY/UiVmmbbzz9Up8=
|
||||
|
@ -122,8 +120,8 @@ github.com/golang/geo v0.0.0-20190916061304-5b978397cfec h1:lJwO/92dFXWeXOZdoGXg
|
|||
github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
|
||||
github.com/golang/geo v0.0.0-20200319012246-673a6f80352d h1:C/hKUcHT483btRbeGkrRjJz+Zbcj8audldIi9tRJDCc=
|
||||
github.com/golang/geo v0.0.0-20200319012246-673a6f80352d/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
|
||||
github.com/golang/geo v0.0.0-20200730024412-e86565bf3f35 h1:enTowfyfjtomBQhxX9mhUD+0tZhpe4rIzStO4aNlou8=
|
||||
github.com/golang/geo v0.0.0-20200730024412-e86565bf3f35/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
|
||||
github.com/golang/geo v0.0.0-20210108004804-a63082ebfb66 h1:wNA26/2ftrz6nI4dbIim6OSKtLlNdjpNiwFB+l/yqtQ=
|
||||
github.com/golang/geo v0.0.0-20210108004804-a63082ebfb66/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
|
@ -156,10 +154,6 @@ github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
|
|||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/google/open-location-code/go v0.0.0-20200929001750-55940b489b0e h1:4uxz0FYvlWWDVHL8AwebLKe3QbdBWLbokZCqBKoHgVA=
|
||||
github.com/google/open-location-code/go v0.0.0-20200929001750-55940b489b0e/go.mod h1:eJfRN6aj+kR/rnua/rw9jAgYhqoMHldQkdTi+sePRKk=
|
||||
github.com/google/open-location-code/go v0.0.0-20201207181708-05e278b06e60 h1:MRqlICg6Tdh9bFXx48l3J76+ARRWQFlMhd70ONhUEHs=
|
||||
github.com/google/open-location-code/go v0.0.0-20201207181708-05e278b06e60/go.mod h1:eJfRN6aj+kR/rnua/rw9jAgYhqoMHldQkdTi+sePRKk=
|
||||
github.com/google/open-location-code/go v0.0.0-20201229230907-d47d9f9b95e9 h1:9giiAmczhkdgh1p9riU7PFmLXpJkq1D4wkIWmEJFMEk=
|
||||
github.com/google/open-location-code/go v0.0.0-20201229230907-d47d9f9b95e9/go.mod h1:eJfRN6aj+kR/rnua/rw9jAgYhqoMHldQkdTi+sePRKk=
|
||||
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
|
@ -281,16 +275,8 @@ github.com/studio-b12/gowebdav v0.0.0-20200929080739-bdacfab94796 h1:vkok9HUaplV
|
|||
github.com/studio-b12/gowebdav v0.0.0-20200929080739-bdacfab94796/go.mod h1:gCcfDlA1Y7GqOaeEKw5l9dOGx1VLdc/HuQSlQAaZ30s=
|
||||
github.com/tensorflow/tensorflow v1.15.2 h1:7/f/A664Tml/nRJg04+p3StcrsT53mkcvmxYHXI21Qo=
|
||||
github.com/tensorflow/tensorflow v1.15.2/go.mod h1:itOSERT4trABok4UOoG+X4BoKds9F3rIsySdn+Lvu90=
|
||||
github.com/tidwall/gjson v1.6.3 h1:aHoiiem0dr7GHkW001T1SMTJ7X5PvyekH5WX0whWGnI=
|
||||
github.com/tidwall/gjson v1.6.3/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0=
|
||||
github.com/tidwall/gjson v1.6.4 h1:JKsCsJqRVFz8eYCsQ5E/ANRbK6CanAtA9IUvGsXklyo=
|
||||
github.com/tidwall/gjson v1.6.4/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0=
|
||||
github.com/tidwall/gjson v1.6.7 h1:Mb1M9HZCRWEcXQ8ieJo7auYyyiSux6w9XN3AdTpxJrE=
|
||||
github.com/tidwall/gjson v1.6.7/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
|
||||
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
|
||||
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
|
||||
github.com/tidwall/match v1.0.2 h1:uuqvHuBGSedK7awZ2YoAtpnimfwBGFjHuWLuLqQj+bU=
|
||||
github.com/tidwall/match v1.0.2/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
|
||||
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
|
||||
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
|
||||
|
@ -315,12 +301,6 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
|
|||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9 h1:umElSU9WZirRdgu2yFHY0ayQkEnKiOC1TtM3fWXFnoU=
|
||||
golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201217014255-9d1352758620 h1:3wPMTskHO3+O6jqTEXyFcsnuxMQOqYSaHsDxcbUXpqA=
|
||||
golang.org/x/crypto v0.0.0-20201217014255-9d1352758620/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
|
@ -376,10 +356,6 @@ golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/
|
|||
golang.org/x/net v0.0.0-20200513185701-a91f0712d120 h1:EZ3cVSzKOlJxAd8e8YAJ7no8nNypTxexh/YE/xW3ZEY=
|
||||
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
|
||||
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20201216054612-986b41b23924 h1:QsnDpLLOKwHBBDa8nDws4DYNc/ryVW2vCpxCs09d4PY=
|
||||
golang.org/x/net v0.0.0-20201216054612-986b41b23924/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw=
|
||||
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
|
@ -411,10 +387,6 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201008063127-280f808b4a53 h1:oY/NCLjoZph2rq+dNr2Xv5Qz2o8r1igXkvcGvz3EDsg=
|
||||
golang.org/x/sys v0.0.0-20201008063127-280f808b4a53/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path"
|
||||
|
@ -20,6 +19,11 @@ import (
|
|||
"github.com/photoprism/photoprism/pkg/fs"
|
||||
)
|
||||
|
||||
// Namespaces for caching and logs.
|
||||
const (
|
||||
accountFolder = "account-folder"
|
||||
)
|
||||
|
||||
// GET /api/v1/accounts
|
||||
func GetAccounts(router *gin.RouterGroup) {
|
||||
router.GET("/accounts", func(c *gin.Context) {
|
||||
|
@ -113,19 +117,16 @@ func GetAccountFolders(router *gin.RouterGroup) {
|
|||
|
||||
start := time.Now()
|
||||
id := ParseUint(c.Param("id"))
|
||||
cache := service.BigCache()
|
||||
cacheKey := fmt.Sprintf("account-folders:%d", id)
|
||||
cache := service.FolderCache()
|
||||
cacheKey := fmt.Sprintf("%s:%d", accountFolder, id)
|
||||
|
||||
if cacheData, err := cache.Get(cacheKey); err == nil {
|
||||
var cached fs.FileInfos
|
||||
if cacheData, ok := cache.Get(cacheKey); ok {
|
||||
cached := cacheData.(fs.FileInfos)
|
||||
|
||||
if err := json.Unmarshal(cacheData, &cached); err != nil {
|
||||
log.Errorf("account-folders: %s", err)
|
||||
} else {
|
||||
log.Debugf("cache hit for %s [%s]", cacheKey, time.Since(start))
|
||||
c.JSON(http.StatusOK, cached)
|
||||
return
|
||||
}
|
||||
log.Debugf("cache hit for %s [%s]", cacheKey, time.Since(start))
|
||||
|
||||
c.JSON(http.StatusOK, cached)
|
||||
return
|
||||
}
|
||||
|
||||
m, err := query.AccountByID(id)
|
||||
|
@ -138,15 +139,13 @@ func GetAccountFolders(router *gin.RouterGroup) {
|
|||
list, err := m.Directories()
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("account-folders: %s", err.Error())
|
||||
log.Errorf("%s: %s", accountFolder, err.Error())
|
||||
Abort(c, http.StatusBadRequest, i18n.ErrConnectionFailed)
|
||||
return
|
||||
}
|
||||
|
||||
if c, err := json.Marshal(list); err == nil {
|
||||
logError("account-folders", cache.Set(cacheKey, c))
|
||||
log.Debugf("cached %s [%s]", cacheKey, time.Since(start))
|
||||
}
|
||||
cache.SetDefault(cacheKey, list)
|
||||
log.Debugf("cached %s [%s]", cacheKey, time.Since(start))
|
||||
|
||||
c.JSON(http.StatusOK, list)
|
||||
})
|
||||
|
|
|
@ -36,6 +36,17 @@ func CacheKey(ns, uid, name string) string {
|
|||
return fmt.Sprintf("%s:%s:%s", ns, uid, name)
|
||||
}
|
||||
|
||||
// RemoveFromFolderCache removes an item from the folder cache e.g. after indexing.
|
||||
func RemoveFromFolderCache(rootName string) {
|
||||
cache := service.FolderCache()
|
||||
|
||||
cacheKey := fmt.Sprintf("folder:%s:%t:%t", rootName, true, false)
|
||||
|
||||
cache.Delete(cacheKey)
|
||||
|
||||
log.Debugf("removed %s from cache", cacheKey)
|
||||
}
|
||||
|
||||
// RemoveFromAlbumCoverCache removes covers by album UID e.g. after adding or removing photos.
|
||||
func RemoveFromAlbumCoverCache(uid string) {
|
||||
cache := service.CoverCache()
|
||||
|
|
|
@ -117,7 +117,7 @@ func AlbumCover(router *gin.RouterGroup) {
|
|||
return
|
||||
}
|
||||
|
||||
cache.Set(cacheKey, ThumbCache{thumbnail, f.ShareBase()}, time.Hour)
|
||||
cache.SetDefault(cacheKey, ThumbCache{thumbnail, f.ShareBase()})
|
||||
log.Debugf("cached %s [%s]", cacheKey, time.Since(start))
|
||||
|
||||
AddCoverCacheHeader(c)
|
||||
|
@ -229,7 +229,7 @@ func LabelCover(router *gin.RouterGroup) {
|
|||
return
|
||||
}
|
||||
|
||||
cache.Set(cacheKey, ThumbCache{thumbnail, f.ShareBase()}, time.Hour)
|
||||
cache.SetDefault(cacheKey, ThumbCache{thumbnail, f.ShareBase()})
|
||||
log.Debugf("cached %s [%s]", cacheKey, time.Since(start))
|
||||
|
||||
AddCoverCacheHeader(c)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
@ -24,17 +23,6 @@ type FoldersResponse struct {
|
|||
Cached bool `json:"cached,omitempty"`
|
||||
}
|
||||
|
||||
// ClearFoldersCache removes folder lists from cache e.g. after indexing.
|
||||
func ClearFoldersCache(rootName string) {
|
||||
cache := service.BigCache()
|
||||
|
||||
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) {
|
||||
|
@ -55,31 +43,28 @@ func GetFolders(router *gin.RouterGroup, urlPath, rootName, rootPath string) {
|
|||
return
|
||||
}
|
||||
|
||||
cache := service.BigCache()
|
||||
cache := service.FolderCache()
|
||||
recursive := f.Recursive
|
||||
listFiles := f.Files
|
||||
uncached := listFiles || f.Uncached
|
||||
resp := FoldersResponse{Root: rootName, Recursive: recursive, Cached: !uncached}
|
||||
path := c.Param("path")
|
||||
|
||||
cacheKey := fmt.Sprintf("folders:%s:%t:%t", filepath.Join(rootName, path), recursive, listFiles)
|
||||
cacheKey := fmt.Sprintf("folder:%s:%t:%t", filepath.Join(rootName, path), recursive, listFiles)
|
||||
|
||||
if !uncached {
|
||||
if cacheData, err := cache.Get(cacheKey); err == nil {
|
||||
var cached FoldersResponse
|
||||
if cacheData, ok := cache.Get(cacheKey); ok {
|
||||
cached := cacheData.(FoldersResponse)
|
||||
|
||||
if err := json.Unmarshal(cacheData, &cached); err != nil {
|
||||
log.Errorf("folders: %s", err)
|
||||
} else {
|
||||
log.Debugf("cache hit for %s [%s]", cacheKey, time.Since(start))
|
||||
c.JSON(http.StatusOK, cached)
|
||||
return
|
||||
}
|
||||
log.Debugf("cache hit for %s [%s]", cacheKey, time.Since(start))
|
||||
|
||||
c.JSON(http.StatusOK, cached)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if folders, err := query.FoldersByPath(rootName, rootPath, path, recursive); err != nil {
|
||||
log.Errorf("folders: %s", err)
|
||||
log.Errorf("folder: %s", err)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
} else {
|
||||
|
@ -88,17 +73,15 @@ func GetFolders(router *gin.RouterGroup, urlPath, rootName, rootPath string) {
|
|||
|
||||
if listFiles {
|
||||
if files, err := query.FilesByPath(f.Count, f.Offset, rootName, path); err != nil {
|
||||
log.Errorf("folders: %s", err)
|
||||
log.Errorf("folder: %s", err)
|
||||
} else {
|
||||
resp.Files = files
|
||||
}
|
||||
}
|
||||
|
||||
if !uncached {
|
||||
if c, err := json.Marshal(resp); err == nil {
|
||||
logError("folders", cache.Set(cacheKey, c))
|
||||
log.Debugf("cached %s [%s]", cacheKey, time.Since(start))
|
||||
}
|
||||
cache.SetDefault(cacheKey, resp)
|
||||
log.Debugf("cached %s [%s]", cacheKey, time.Since(start))
|
||||
}
|
||||
|
||||
AddFileCountHeaders(c, len(resp.Files), len(resp.Folders))
|
||||
|
|
|
@ -60,7 +60,7 @@ func StartImport(router *gin.RouterGroup) {
|
|||
|
||||
imp := service.Import()
|
||||
|
||||
ClearFoldersCache(entity.RootImport)
|
||||
RemoveFromFolderCache(entity.RootImport)
|
||||
|
||||
var opt photoprism.ImportOptions
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ func StartIndexing(router *gin.RouterGroup) {
|
|||
|
||||
indexed := ind.Start(indOpt)
|
||||
|
||||
ClearFoldersCache(entity.RootOriginals)
|
||||
RemoveFromFolderCache(entity.RootOriginals)
|
||||
|
||||
prg := service.Purge()
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ func GetThumb(router *gin.RouterGroup) {
|
|||
return
|
||||
}
|
||||
|
||||
cache.Set(cacheKey, ThumbCache{thumbnail, f.ShareBase()}, time.Hour * 24)
|
||||
cache.SetDefault(cacheKey, ThumbCache{thumbnail, f.ShareBase()})
|
||||
log.Debugf("cached %s [%s]", cacheKey, time.Since(start))
|
||||
|
||||
AddThumbCacheHeader(c)
|
||||
|
|
|
@ -64,7 +64,7 @@ func Import() error {
|
|||
|
||||
imp := service.Import()
|
||||
|
||||
api.ClearFoldersCache(entity.RootImport)
|
||||
api.RemoveFromFolderCache(entity.RootImport)
|
||||
|
||||
event.InfoMsg(i18n.MsgCopyingFilesFrom, txt.Quote(filepath.Base(path)))
|
||||
opt := photoprism.ImportOptionsCopy(path)
|
||||
|
|
|
@ -72,7 +72,7 @@ func Index() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
api.ClearFoldersCache(entity.RootOriginals)
|
||||
api.RemoveFromFolderCache(entity.RootOriginals)
|
||||
|
||||
prg := service.Purge()
|
||||
|
||||
|
|
|
@ -3,17 +3,7 @@ package places
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/allegro/bigcache"
|
||||
gc "github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
var cache *bigcache.BigCache
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
|
||||
cache, err = bigcache.NewBigCache(bigcache.DefaultConfig(time.Hour))
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("")
|
||||
}
|
||||
}
|
||||
var cache = gc.New(time.Hour*4, 10*time.Minute)
|
||||
|
|
|
@ -57,15 +57,11 @@ func FindLocation(id string) (result Location, err error) {
|
|||
return result, fmt.Errorf("skipping lat %f, lng %f (%s)", lat, lng, ApiName)
|
||||
}
|
||||
|
||||
if hit, err := cache.Get(id); err == nil {
|
||||
if hit, ok := cache.Get(id); ok {
|
||||
log.Debugf("places: cache hit for lat %f, lng %f", lat, lng)
|
||||
var cached Location
|
||||
if err := json.Unmarshal(hit, &cached); err != nil {
|
||||
log.Errorf("places: %s", err.Error())
|
||||
} else {
|
||||
cached.Cached = true
|
||||
return cached, nil
|
||||
}
|
||||
cached := hit.(Location)
|
||||
cached.Cached = true
|
||||
return cached, nil
|
||||
}
|
||||
|
||||
url := fmt.Sprintf(ReverseLookupURL, id)
|
||||
|
@ -115,13 +111,8 @@ func FindLocation(id string) (result Location, err error) {
|
|||
return result, fmt.Errorf("no result for %s (%s)", id, ApiName)
|
||||
}
|
||||
|
||||
if cached, err := json.Marshal(result); err == nil {
|
||||
if err := cache.Set(id, cached); err != nil {
|
||||
log.Errorf("places: %s (cache)", err)
|
||||
} else {
|
||||
log.Debugf("places: cached cell %s [%s]", id, time.Since(start))
|
||||
}
|
||||
}
|
||||
cache.SetDefault(id, result)
|
||||
log.Debugf("places: cached cell %s [%s]", id, time.Since(start))
|
||||
|
||||
result.Cached = false
|
||||
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/allegro/bigcache"
|
||||
)
|
||||
|
||||
var onceBigCache sync.Once
|
||||
|
||||
func initBigCache() {
|
||||
var err error
|
||||
|
||||
services.BigCache, err = bigcache.NewBigCache(bigcache.DefaultConfig(time.Hour))
|
||||
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func BigCache() *bigcache.BigCache {
|
||||
onceBigCache.Do(initBigCache)
|
||||
|
||||
return services.BigCache
|
||||
}
|
20
internal/service/folder-cache.go
Normal file
20
internal/service/folder-cache.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
gc "github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
var onceFolderCache sync.Once
|
||||
|
||||
func initFolderCache() {
|
||||
services.FolderCache = gc.New(time.Minute*15, 5*time.Minute)
|
||||
}
|
||||
|
||||
func FolderCache() *gc.Cache {
|
||||
onceFolderCache.Do(initFolderCache)
|
||||
|
||||
return services.FolderCache
|
||||
}
|
|
@ -1,10 +1,8 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"github.com/allegro/bigcache"
|
||||
"github.com/photoprism/photoprism/internal/classify"
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/nsfw"
|
||||
"github.com/photoprism/photoprism/internal/photoprism"
|
||||
"github.com/photoprism/photoprism/internal/query"
|
||||
|
@ -13,25 +11,24 @@ import (
|
|||
gc "github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
var log = event.Log
|
||||
var conf *config.Config
|
||||
|
||||
var services struct {
|
||||
BigCache *bigcache.BigCache
|
||||
CoverCache *gc.Cache
|
||||
ThumbCache *gc.Cache
|
||||
Classify *classify.TensorFlow
|
||||
Convert *photoprism.Convert
|
||||
Files *photoprism.Files
|
||||
Photos *photoprism.Photos
|
||||
Import *photoprism.Import
|
||||
Index *photoprism.Index
|
||||
Moments *photoprism.Moments
|
||||
Purge *photoprism.Purge
|
||||
Nsfw *nsfw.Detector
|
||||
Query *query.Query
|
||||
Resample *photoprism.Resample
|
||||
Session *session.Session
|
||||
FolderCache *gc.Cache
|
||||
CoverCache *gc.Cache
|
||||
ThumbCache *gc.Cache
|
||||
Classify *classify.TensorFlow
|
||||
Convert *photoprism.Convert
|
||||
Files *photoprism.Files
|
||||
Photos *photoprism.Photos
|
||||
Import *photoprism.Import
|
||||
Index *photoprism.Index
|
||||
Moments *photoprism.Moments
|
||||
Purge *photoprism.Purge
|
||||
Nsfw *nsfw.Detector
|
||||
Query *query.Query
|
||||
Resample *photoprism.Resample
|
||||
Session *session.Session
|
||||
}
|
||||
|
||||
func SetConfig(c *config.Config) {
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/allegro/bigcache"
|
||||
gc "github.com/patrickmn/go-cache"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/classify"
|
||||
|
@ -33,8 +32,8 @@ func TestConfig(t *testing.T) {
|
|||
assert.Equal(t, conf, Config())
|
||||
}
|
||||
|
||||
func TestBigCache(t *testing.T) {
|
||||
assert.IsType(t, &bigcache.BigCache{}, BigCache())
|
||||
func TestFolderCache(t *testing.T) {
|
||||
assert.IsType(t, &gc.Cache{}, FolderCache())
|
||||
}
|
||||
|
||||
func TestCoverCache(t *testing.T) {
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
var onceThumbCache sync.Once
|
||||
|
||||
func initThumbCache() {
|
||||
services.ThumbCache = gc.New(time.Hour, 10*time.Minute)
|
||||
services.ThumbCache = gc.New(time.Hour*24, 10*time.Minute)
|
||||
}
|
||||
|
||||
func ThumbCache() *gc.Cache {
|
||||
|
|
Loading…
Add table
Reference in a new issue