From 8abfdc82b2272439bf8355e894099ab20a72d34e Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Fri, 8 Feb 2019 17:37:35 -0500 Subject: [PATCH] faster blob manager startup --- lbrynet/blob/blob_manager.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lbrynet/blob/blob_manager.py b/lbrynet/blob/blob_manager.py index f079ccb8f..73c2b0573 100644 --- a/lbrynet/blob/blob_manager.py +++ b/lbrynet/blob/blob_manager.py @@ -1,9 +1,10 @@ +import os import typing import asyncio import logging from sqlite3 import IntegrityError from lbrynet.extras.daemon.storage import SQLiteStorage -from lbrynet.blob.blob_file import BlobFile +from lbrynet.blob.blob_file import BlobFile, is_valid_blobhash from lbrynet.stream.descriptor import StreamDescriptor if typing.TYPE_CHECKING: @@ -30,8 +31,11 @@ class BlobFileManager: self.blobs: typing.Dict[str, BlobFile] = {} async def setup(self) -> bool: - raw_blob_hashes = await self.get_all_verified_blobs() - self.completed_blob_hashes.update(raw_blob_hashes) + def initialize_blob_hashes(): + self.completed_blob_hashes.update( + item.name for item in os.scandir(self.blob_dir) if is_valid_blobhash(item.name) + ) + await self.loop.run_in_executor(None, initialize_blob_hashes) return True def get_blob(self, blob_hash, length: typing.Optional[int] = None): @@ -59,10 +63,6 @@ class BlobFileManager: blobs = [self.get_blob(b) for b in blob_hashes] return [blob.blob_hash for blob in blobs if blob.get_is_verified()] - async def get_all_verified_blobs(self) -> typing.List[str]: - blob_hashes = await self.storage.get_all_blob_hashes() - return self.check_completed_blobs(blob_hashes) - async def delete_blob(self, blob_hash: str): try: blob = self.get_blob(blob_hash)