perf(lanzou): optimize the use of list cache (#2956)

* fix:local sort not cache

* perf(lanzou): Optimize the use of list cache
This commit is contained in:
foxxorcat
2023-01-08 21:31:35 +08:00
committed by GitHub
parent 99a186d01b
commit 2f19d4a834
7 changed files with 117 additions and 33 deletions

View File

@ -1,8 +1,37 @@
package utils
import "time"
import (
"sync"
"time"
)
func MustParseCNTime(str string) time.Time {
lastOpTime, _ := time.ParseInLocation("2006-01-02 15:04:05 -07", str+" +08", time.Local)
return lastOpTime
}
func NewDebounce(interval time.Duration) func(f func()) {
var timer *time.Timer
var lock sync.Mutex
return func(f func()) {
lock.Lock()
defer lock.Unlock()
if timer != nil {
timer.Stop()
}
timer = time.AfterFunc(interval, f)
}
}
func NewDebounce2(interval time.Duration, f func()) func() {
var timer *time.Timer
var lock sync.Mutex
return func() {
lock.Lock()
defer lock.Unlock()
if timer == nil {
timer = time.AfterFunc(interval, f)
}
(*time.Timer)(timer).Reset(interval)
}
}