optimize store.write (#12494)

This commit is contained in:
Shi Wenbin 2022-07-11 23:57:08 +08:00 committed by GitHub
parent ef6c1be98a
commit 73d50258d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -101,6 +101,11 @@ func (store *Store) Write() {
store.mtx.Lock()
defer store.mtx.Unlock()
if len(store.cache) == 0 && len(store.deleted) == 0 && len(store.unsortedCache) == 0 {
store.sortedCache = dbm.NewMemDB()
return
}
// We need a copy of all of the keys.
// Not the best, but probably not a bottleneck depending.
keys := make([]string, 0, len(store.cache))