diff --git a/dcache/manager.go b/dcache/manager.go index ba7dbea..ed0dd76 100644 --- a/dcache/manager.go +++ b/dcache/manager.go @@ -51,14 +51,14 @@ func NewManager(db *storage.DBClient, chain string) *Manager { return e } - e.initInscriptionCache() - e.initInscriptionStatsCache() - e.initBalanceCache() + e.initInscriptionCache(chain) + e.initInscriptionStatsCache(chain) + e.initBalanceCache(chain) e.initUtxoCache() return e } -func (h *Manager) initInscriptionCache() { +func (h *Manager) initInscriptionCache(chain string) { h.Inscription = NewInscription() startTs := time.Now() @@ -68,7 +68,7 @@ func (h *Manager) initInscriptionCache() { maxSid := uint32(0) xylog.Logger.Infof("load inscriptions data start...") for { - items, err := h.db.GetInscriptionsByIdLimit(uint64(start), limit) + items, err := h.db.GetInscriptionsByIdLimit(chain, uint64(start), limit) if err != nil { xylog.Logger.Fatalf("failed to initialize inscription cache data. err:%v", err) } @@ -103,7 +103,7 @@ func (h *Manager) initInscriptionCache() { xylog.Logger.Infof("load inscriptions data finished, cost ts:%v", time.Since(startTs)) } -func (h *Manager) initInscriptionStatsCache() { +func (h *Manager) initInscriptionStatsCache(chain string) { h.InscriptionStats = NewInscriptionStats() startTs := time.Now() @@ -113,7 +113,7 @@ func (h *Manager) initInscriptionStatsCache() { maxSid := uint32(0) xylog.Logger.Infof("load inscription-stats data start...") for { - items, err := h.db.GetInscriptionStatsByIdLimit(uint64(start), limit) + items, err := h.db.GetInscriptionStatsByIdLimit(chain, uint64(start), limit) if err != nil { xylog.Logger.Fatalf("failed to initialize inscription-stats cache data. err:%v", err) } @@ -147,7 +147,7 @@ func (h *Manager) initInscriptionStatsCache() { xylog.Logger.Infof("load inscription-stats data finished, cost ts:%v", time.Since(startTs)) } -func (h *Manager) initBalanceCache() { +func (h *Manager) initBalanceCache(chain string) { h.Balance = NewBalance() startTs := time.Now() @@ -157,7 +157,7 @@ func (h *Manager) initBalanceCache() { maxSid := uint64(0) xylog.Logger.Infof("load balances data start...") for { - balances, err := h.db.GetBalancesByIdLimit(start, limit) + balances, err := h.db.GetBalancesByIdLimit(chain, start, limit) if err != nil { xylog.Logger.Fatalf("failed to initialize balance cache data. err:%v", err) } diff --git a/explorer/scan.go b/explorer/scan.go index 55b1aa5..e8c054e 100644 --- a/explorer/scan.go +++ b/explorer/scan.go @@ -78,7 +78,7 @@ func NewExplorer(rpcClient xycommon.IRPCClient, dbc *storage.DBClient, cfg *conf fromBlock: cfg.Scan.StartBlock, mu: sync.Mutex{}, dCache: dCache, - blocks: make(chan *xycommon.RpcBlock, 1024), + blocks: make(chan *xycommon.RpcBlock, 100), txResultHandler: txResultHandler, scanChn: make(chan uint64, 4), @@ -141,7 +141,7 @@ func (e *Explorer) Scan() { continue } - if e.currentBlock-blockNumber > 500 { + if e.currentBlock-blockNumber > 100 { endBlock := blockNumber + scanLimit if e.config.Scan.BatchWorkers > 0 { endBlock = blockNumber + e.config.Scan.BatchWorkers diff --git a/storage/common.go b/storage/common.go index 313316c..82590a5 100644 --- a/storage/common.go +++ b/storage/common.go @@ -375,18 +375,18 @@ func (conn *DBClient) GetInscriptions(limit, offset int, chain, protocol, tick, return data, total, nil } -func (conn *DBClient) GetInscriptionsByIdLimit(start uint64, limit int) ([]model.Inscriptions, error) { +func (conn *DBClient) GetInscriptionsByIdLimit(chain string, start uint64, limit int) ([]model.Inscriptions, error) { inscriptions := make([]model.Inscriptions, 0) - err := conn.SqlDB.Where("id > ?", start).Order("id asc").Limit(limit).Find(&inscriptions).Error + err := conn.SqlDB.Where("chain = ?", chain).Where("id > ?", start).Order("id asc").Limit(limit).Find(&inscriptions).Error if err != nil { return nil, err } return inscriptions, nil } -func (conn *DBClient) GetInscriptionStatsByIdLimit(start uint64, limit int) ([]model.InscriptionsStats, error) { +func (conn *DBClient) GetInscriptionStatsByIdLimit(chain string, start uint64, limit int) ([]model.InscriptionsStats, error) { stats := make([]model.InscriptionsStats, 0) - err := conn.SqlDB.Where("id > ?", start).Order("id asc").Limit(limit).Find(&stats).Error + err := conn.SqlDB.Where("chain = ?", chain).Where("id > ?", start).Order("id asc").Limit(limit).Find(&stats).Error if err != nil { return nil, err } @@ -520,9 +520,9 @@ func (conn *DBClient) GetUTXOCount(address, chain, protocol, tick string) (int64 return count, nil } -func (conn *DBClient) GetBalancesByIdLimit(start uint64, limit int) ([]model.Balances, error) { +func (conn *DBClient) GetBalancesByIdLimit(chain string, start uint64, limit int) ([]model.Balances, error) { balances := make([]model.Balances, 0) - err := conn.SqlDB.Where("id > ?", start).Order("id asc").Limit(limit).Find(&balances).Error + err := conn.SqlDB.Where("chain = ?", chain).Where("id > ?", start).Order("id asc").Limit(limit).Find(&balances).Error if err != nil { return nil, err }