fix getting chunk bug and change query from database to in-memory which
improve the speed by more than 1000 times