mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	优化索引数据库关闭速度
This commit is contained in:
		@@ -5,6 +5,7 @@ package caches
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeNode/internal/goman"
 | 
						"github.com/TeaOSLab/EdgeNode/internal/goman"
 | 
				
			||||||
 | 
						"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeNode/internal/utils/fnv"
 | 
						"github.com/TeaOSLab/EdgeNode/internal/utils/fnv"
 | 
				
			||||||
	"github.com/iwind/TeaGo/types"
 | 
						"github.com/iwind/TeaGo/types"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
@@ -37,14 +38,23 @@ func NewKVFileList(dir string) *KVFileList {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Init 初始化
 | 
					// Init 初始化
 | 
				
			||||||
func (this *KVFileList) Init() error {
 | 
					func (this *KVFileList) Init() error {
 | 
				
			||||||
	for _, store := range this.stores {
 | 
						remotelogs.Println("CACHE", "loading database from '"+this.dir+"' ...")
 | 
				
			||||||
		err := store.Open()
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return fmt.Errorf("open store '"+store.Path()+"' failed: %w", err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return nil
 | 
						var group = goman.NewTaskGroup()
 | 
				
			||||||
 | 
						var lastErr error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, store := range this.stores {
 | 
				
			||||||
 | 
							var storeCopy = store
 | 
				
			||||||
 | 
							group.Run(func() {
 | 
				
			||||||
 | 
								err := storeCopy.Open()
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									lastErr = fmt.Errorf("open store '"+storeCopy.Path()+"' failed: %w", err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						group.Wait()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return lastErr
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Reset 重置数据
 | 
					// Reset 重置数据
 | 
				
			||||||
@@ -266,12 +276,17 @@ func (this *KVFileList) OnRemove(fn func(item *Item)) {
 | 
				
			|||||||
// Close 关闭
 | 
					// Close 关闭
 | 
				
			||||||
func (this *KVFileList) Close() error {
 | 
					func (this *KVFileList) Close() error {
 | 
				
			||||||
	var lastErr error
 | 
						var lastErr error
 | 
				
			||||||
 | 
						var group = goman.NewTaskGroup()
 | 
				
			||||||
	for _, store := range this.stores {
 | 
						for _, store := range this.stores {
 | 
				
			||||||
		err := store.Close()
 | 
							var storeCopy = store
 | 
				
			||||||
		if err != nil {
 | 
							group.Run(func() {
 | 
				
			||||||
			lastErr = err
 | 
								err := storeCopy.Close()
 | 
				
			||||||
		}
 | 
								if err != nil {
 | 
				
			||||||
 | 
									lastErr = err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						group.Wait()
 | 
				
			||||||
	return lastErr
 | 
						return lastErr
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -406,11 +406,16 @@ func (this *SQLiteFileList) OnRemove(f func(item *Item)) {
 | 
				
			|||||||
func (this *SQLiteFileList) Close() error {
 | 
					func (this *SQLiteFileList) Close() error {
 | 
				
			||||||
	this.memoryCache.Destroy()
 | 
						this.memoryCache.Destroy()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var group = goman.NewTaskGroup()
 | 
				
			||||||
	for _, db := range this.dbList {
 | 
						for _, db := range this.dbList {
 | 
				
			||||||
		if db != nil {
 | 
							var dbCopy = db
 | 
				
			||||||
			_ = db.Close()
 | 
							group.Run(func() {
 | 
				
			||||||
		}
 | 
								if dbCopy != nil {
 | 
				
			||||||
 | 
									_ = dbCopy.Close()
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						group.Wait()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user