func (db *Database) PurgeOldInfos(poolName string, purgeCount int) error {
	poolName = strings.ToLower(poolName)
	db.namedLock.Lock(poolName)
	defer db.namedLock.Unlock(poolName)

	return db.db.Transaction(func(tx *gorm.DB) error {
		var pool Pool
		if err := tx.Model(&Pool{}).Where("name = ?", poolName).First(&pool).Error; err != nil {
			return err
		}
		// no need to purge
		if len(pool.Infos) < purgeCount {
			return nil
		}
		//var bigInts sortutil.BigIntSlice
		bigInts := make(sortutil.BigIntSlice, 0, len(pool.Infos))
		for blockNum := range pool.Infos {
			bigBlockNum, ok := new(big.Int).SetString(blockNum, 10)
			if !ok {
				return errors.New("failed to convert block number from string to big.Int")
			}
			bigInts = append(bigInts, bigBlockNum)
		}
		bigInts.Sort()
		for i := 0; i < purgeCount; i++ {
			delete(pool.Infos, bigInts[i].String())

		}
		return tx.Save(&pool).Error
	})
}
// PurgeOldInfos is used to purge old information from the database
PurgeOldInfos is used to purge old information from the database
// PurgeOldInfos is used to purge old information from the database
func (db *Database) PurgeOldInfos(poolName string, purgeCount int) error {
	poolName = strings.ToLower(poolName)
	db.namedLock.Lock(poolName)
	defer db.namedLock.Unlock(poolName)
	return db.db.Transaction(func(tx *gorm.DB) error {
		var pool Pool
		if err := tx.Model(&Pool{}).Where("name = ?", poolName).First(&pool).Error; err != nil {
			return err
		}
		if len(pool.Infos) < purgeCount {
			return nil
		}
		bigInts := make(sortutil.BigIntSlice, 0, len(pool.Infos))
		for blockNum := range pool.Infos {
			bigBlockNum, ok := new(big.Int).SetString(blockNum, 10)
			if !ok {
				return errors.New("failed to convert block number from string to big.Int")
			}
			bigInts = append(bigInts, bigBlockNum)
		}
		bigInts.Sort()
		for i := 0; i < purgeCount; i++ {
			delete(pool.Infos, bigInts[i].String())
		}
		return tx.Save(&pool).Error
	})
}
func ( db * Database ) PurgeOldInfos ( poolName string , purgeCount int ) error { poolName = strings . ToLower ( poolName ) db . namedLock . Lock ( poolName ) defer db . namedLock . Unlock ( poolName ) return db . db . Transaction ( func ( tx * gorm . DB ) error { var pool Pool if err := tx . Model ( & Pool { } ) . Where ( " " , poolName ) . First ( & pool ) . Error ; err != nil { return err } if len ( pool . Infos ) < purgeCount { return nil } bigInts := make ( sortutil . BigIntSlice , 0 , len ( pool . Infos ) ) for blockNum := range pool . Infos { bigBlockNum , ok := new ( big . Int ) . SetString ( blockNum , 10 ) if ! ok { return errors . New ( " " ) } bigInts = append ( bigInts , bigBlockNum ) } bigInts . Sort ( ) for i := 0 ; i < purgeCount ; i ++ { delete ( pool . Infos , bigInts [ i ] . String ( ) ) } return tx . Save ( & pool ) . Error } ) }
PurgeOldInfos is used to purge old information from the database
PurgeOldInfos is used to purge old information from the database
// no need to purge //var bigInts sortutil.BigIntSlice