🐛 插入/更新资源文件导致内核崩溃 https://github.com/siyuan-note/siyuan/issues/5574
This commit is contained in:
parent
c0df1e50d4
commit
caf2dc5231
6 changed files with 19 additions and 16 deletions
6
app/stage/protyle/js/lute/lute.min.js
vendored
6
app/stage/protyle/js/lute/lute.min.js
vendored
File diff suppressed because one or more lines are too long
11
kernel/cache/asset.go
vendored
11
kernel/cache/asset.go
vendored
|
@ -33,11 +33,14 @@ type Asset struct {
|
|||
Updated int64 `json:"updated"`
|
||||
}
|
||||
|
||||
var Assets = sync.Map{}
|
||||
var Assets = map[string]*Asset{}
|
||||
var assetsLock = sync.Mutex{}
|
||||
|
||||
func LoadAssets() {
|
||||
start := time.Now()
|
||||
Assets = sync.Map{}
|
||||
assetsLock.Lock()
|
||||
defer assetsLock.Unlock()
|
||||
|
||||
assets := filepath.Join(util.DataDir, "assets")
|
||||
filepath.Walk(assets, func(path string, info fs.FileInfo, err error) error {
|
||||
if info.IsDir() {
|
||||
|
@ -52,11 +55,11 @@ func LoadAssets() {
|
|||
|
||||
hName := util.RemoveID(info.Name())
|
||||
path = filepath.ToSlash(strings.TrimPrefix(path, util.DataDir))[1:]
|
||||
Assets.Store(path, &Asset{
|
||||
Assets[path] = &Asset{
|
||||
HName: hName,
|
||||
Path: path,
|
||||
Updated: info.ModTime().UnixMilli(),
|
||||
})
|
||||
}
|
||||
return nil
|
||||
})
|
||||
elapsed := time.Since(start)
|
||||
|
|
|
@ -7,7 +7,7 @@ require (
|
|||
github.com/88250/css v0.1.2
|
||||
github.com/88250/flock v0.8.2
|
||||
github.com/88250/gulu v1.2.3-0.20220720144315-065ef35ec583
|
||||
github.com/88250/lute v1.7.5-0.20220804014636-564e20b36928
|
||||
github.com/88250/lute v1.7.5-0.20220804075456-e8092b62836e
|
||||
github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1
|
||||
github.com/88250/pdfcpu v0.3.13
|
||||
github.com/88250/protyle v0.0.0-20220519012506-0a2c8dc24397
|
||||
|
|
|
@ -58,8 +58,8 @@ github.com/88250/gulu v1.2.0/go.mod h1:ZhEJ98UjR2y7j2toGj4/b+1rRELcZFQAPq/Yjyin2
|
|||
github.com/88250/gulu v1.2.3-0.20220720144315-065ef35ec583 h1:FhA/zJemLrbOYJpdMIMBezO5rGigQSdPR1kv+aztHfA=
|
||||
github.com/88250/gulu v1.2.3-0.20220720144315-065ef35ec583/go.mod h1:I1qBzsksFL2ciGSuqDE7R3XW4BUMrfDgOvSXEk7FsAI=
|
||||
github.com/88250/lute v1.7.4-0.20220426011157-34c9bfa2e148/go.mod h1:Bdu9LRNjQhtL3TftbtpjIWTwDVAXoS7AD8QsZQPk7zo=
|
||||
github.com/88250/lute v1.7.5-0.20220804014636-564e20b36928 h1:YLPXVaHTG865LNL64XKMM+XTGOwTQfuYGULQ+9keDK4=
|
||||
github.com/88250/lute v1.7.5-0.20220804014636-564e20b36928/go.mod h1:Bdu9LRNjQhtL3TftbtpjIWTwDVAXoS7AD8QsZQPk7zo=
|
||||
github.com/88250/lute v1.7.5-0.20220804075456-e8092b62836e h1:+P2HXo0zba5VaydqM8mSQins1yofqfsy/r/6qfhRxE8=
|
||||
github.com/88250/lute v1.7.5-0.20220804075456-e8092b62836e/go.mod h1:Bdu9LRNjQhtL3TftbtpjIWTwDVAXoS7AD8QsZQPk7zo=
|
||||
github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1 h1:9Cb+iN639vUI2OcIBc+4oGwml9/0J6bL6dWNb8Al+1s=
|
||||
github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1/go.mod h1:jH6MMPr8G7AMzaVmWHXZQiB1DKO3giWbcWZ7UoJ1teI=
|
||||
github.com/88250/pdfcpu v0.3.13 h1:touMWMZkCGalMIbEg9bxYp7rETM+zwb9hXjwhqi4I7Q=
|
||||
|
|
|
@ -167,10 +167,9 @@ func SearchAssetsByName(keyword string) (ret []*cache.Asset) {
|
|||
ret = []*cache.Asset{}
|
||||
|
||||
count := 0
|
||||
cache.Assets.Range(func(k, v interface{}) bool {
|
||||
asset := v.(*cache.Asset)
|
||||
for _, asset := range cache.Assets {
|
||||
if !strings.Contains(strings.ToLower(asset.HName), strings.ToLower(keyword)) {
|
||||
return true
|
||||
continue
|
||||
}
|
||||
|
||||
_, hName := search.MarkText(asset.HName, keyword, 64, Conf.Search.CaseSensitive)
|
||||
|
@ -181,10 +180,9 @@ func SearchAssetsByName(keyword string) (ret []*cache.Asset) {
|
|||
})
|
||||
count++
|
||||
if Conf.Search.Limit <= count {
|
||||
return false
|
||||
return
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
sort.Slice(ret, func(i, j int) bool {
|
||||
return ret[i].Updated > ret[j].Updated
|
||||
|
|
|
@ -53,6 +53,8 @@ func watchAssets() {
|
|||
}
|
||||
|
||||
go func() {
|
||||
logging.Recover()
|
||||
|
||||
var (
|
||||
timer *time.Timer
|
||||
lastEvent fsnotify.Event
|
||||
|
|
Loading…
Add table
Reference in a new issue