🎨 Data repo support for purging unreferenced indexes and objects https://github.com/siyuan-note/siyuan/issues/8054

This commit is contained in:
Liang Ding 2023-04-20 18:54:24 +08:00
parent 71110aeead
commit 38ed2a3300
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
12 changed files with 116 additions and 9 deletions

View file

@ -349,3 +349,15 @@ func resetRepo(c *gin.Context) {
return
}
}
func purgeRepo(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
if err := model.PurgeRepo(); nil != err {
ret.Code = -1
ret.Msg = fmt.Sprintf(model.Conf.Language(201), err.Error())
ret.Data = map[string]interface{}{"closeTimeout": 5000}
return
}
}

View file

@ -296,6 +296,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/repo/initRepoKey", model.CheckAuth, model.CheckReadonly, initRepoKey)
ginServer.Handle("POST", "/api/repo/initRepoKeyFromPassphrase", model.CheckAuth, model.CheckReadonly, initRepoKeyFromPassphrase)
ginServer.Handle("POST", "/api/repo/resetRepo", model.CheckAuth, model.CheckReadonly, resetRepo)
ginServer.Handle("POST", "/api/repo/purgeRepo", model.CheckAuth, model.CheckReadonly, purgeRepo)
ginServer.Handle("POST", "/api/repo/importRepoKey", model.CheckAuth, model.CheckReadonly, importRepoKey)
ginServer.Handle("POST", "/api/repo/createSnapshot", model.CheckAuth, model.CheckReadonly, createSnapshot)
ginServer.Handle("POST", "/api/repo/tagSnapshot", model.CheckAuth, model.CheckReadonly, tagSnapshot)

View file

@ -44,7 +44,7 @@ require (
github.com/radovskyb/watcher v1.0.7
github.com/sashabaranov/go-gpt3 v1.4.0
github.com/shirou/gopsutil/v3 v3.23.2
github.com/siyuan-note/dejavu v0.0.0-20230420022535-782a2dbfb757
github.com/siyuan-note/dejavu v0.0.0-20230420080412-a5dabc68fa8f
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75
github.com/siyuan-note/eventbus v0.0.0-20230216103454-41885eac6c2b
github.com/siyuan-note/filelock v0.0.0-20230417044524-125ee78b5cc9
@ -115,7 +115,7 @@ require (
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect
github.com/quic-go/quic-go v0.33.0 // indirect
github.com/quic-go/quic-go v0.34.0 // indirect
github.com/restic/chunker v0.4.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
github.com/shopspring/decimal v1.3.1 // indirect

View file

@ -258,6 +258,8 @@ github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8G
github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM=
github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y0=
github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA=
github.com/quic-go/quic-go v0.34.0 h1:OvOJ9LFjTySgwOTYUZmNoq0FzVicP8YujpV0kB7m2lU=
github.com/quic-go/quic-go v0.34.0/go.mod h1:+4CVgVppm0FNjpG3UcX8Joi/frKOH7/ciD5yGcwOO1g=
github.com/radovskyb/watcher v1.0.7 h1:AYePLih6dpmS32vlHfhCeli8127LzkIgwJGcwwe8tUE=
github.com/radovskyb/watcher v1.0.7/go.mod h1:78okwvY5wPdzcb1UYnip1pvrZNIVEIh/Cm+ZuvsUYIg=
github.com/restic/chunker v0.4.0 h1:YUPYCUn70MYP7VO4yllypp2SjmsRhRJaad3xKu1QFRw=
@ -281,6 +283,8 @@ github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d h1:lvCTyBbr36+
github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d/go.mod h1:05UtEgK5zq39gLST6uB0cf3NEHjETfB4Fgr3Gx5R9Vw=
github.com/siyuan-note/dejavu v0.0.0-20230420022535-782a2dbfb757 h1:WZ0ahzQ2rLJlry4GgMbVXYyG1tJpmbU2VXsdRZAq/D4=
github.com/siyuan-note/dejavu v0.0.0-20230420022535-782a2dbfb757/go.mod h1:ltB1VyRo4A178+ykH74f3AEUliU0UwC6Dn7Ed6tF/8Y=
github.com/siyuan-note/dejavu v0.0.0-20230420080412-a5dabc68fa8f h1:zAD1wMuJA/6JRUvazVA18tfPo5mTPbY82rOkY+mHicc=
github.com/siyuan-note/dejavu v0.0.0-20230420080412-a5dabc68fa8f/go.mod h1:ltB1VyRo4A178+ykH74f3AEUliU0UwC6Dn7Ed6tF/8Y=
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE=
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
github.com/siyuan-note/eventbus v0.0.0-20230216103454-41885eac6c2b h1:828lTUW2C0uNiolODqoACu7J8sDUzswD4Xo04mUombg=

View file

@ -423,6 +423,29 @@ func ResetRepo() (err error) {
return
}
func PurgeRepo() (err error) {
msg := Conf.Language(202)
util.PushEndlessProgress(msg)
defer util.PushClearProgress()
repo, err := newRepository()
if nil != err {
return
}
stat, err := repo.Purge()
if nil != err {
return
}
deletedIndexes := stat.Indexes
deletedObjects := stat.Objects
deletedSize := humanize.Bytes(uint64(stat.Size))
msg = fmt.Sprintf(Conf.Language(203), deletedIndexes, deletedObjects, deletedSize)
util.PushMsg(msg, 5000)
return
}
func InitRepoKeyFromPassphrase(passphrase string) (err error) {
passphrase = gulu.Str.RemoveInvisible(passphrase)
passphrase = strings.TrimSpace(passphrase)