优化本地数据库相关代码

This commit is contained in:
刘祥超
2023-10-06 20:56:27 +08:00
parent 69e4dd6cfe
commit c460421279
7 changed files with 28 additions and 9 deletions

View File

@@ -18,6 +18,10 @@ import (
"time"
)
const (
SyncMode = "NORMAL"
)
var errDBIsClosed = errors.New("the database is closed")
type DB struct {
@@ -199,6 +203,7 @@ func (this *DB) Close() error {
this.statusLocker.Unlock()
// waiting for updating operations to finish
var maxLoops = 5_000
for {
this.statusLocker.Lock()
var countUpdating = this.countUpdating
@@ -207,6 +212,11 @@ func (this *DB) Close() error {
break
}
time.Sleep(1 * time.Millisecond)
maxLoops--
if maxLoops <= 0 {
break
}
}
for _, batch := range this.batches {