Repository: Chia-Network/chia-blockchain
File: chia/plotting/util.py (Python)

Code before:
            config["harvester"]["decompressor_thread_count"] = decompressor_thread_count
        if recursive_plot_scan is not None:
            config["harvester"]["recursive_plot_scan"] = recursive_plot_scan
        if refresh_parameter is not None:
            config["harvester"]["plots_refresh_parameter"] = refresh_parameter.to_json_dict()

        save_config(root_path, "config.yaml", config)


def get_filenames(directory: Path, recursive: bool, follow_links: bool) -> list[Path]:
    try:
        if not directory.exists():
            log.warning(f"Directory: {directory} does not exist.")
            return []
    except OSError as e:
        log.warning(f"Error checking if directory {directory} exists: {e}")
        return []
    all_files: list[Path] = []
    try:
        if follow_links and recursive:
            import glob

            files = glob.glob(str(directory / "**" / "*.plot"), recursive=True)
            for file in files:
                filepath = Path(file).resolve()
                if filepath.is_file() and not filepath.name.startswith("._"):
                    all_files.append(filepath)
        else:
            glob_function = directory.rglob if recursive else directory.glob
            all_files = [
                child for child in glob_function("*.plot") if child.is_file() and not child.name.startswith("._")
            ]
        log.debug(f"get_filenames: {len(all_files)} files found in {directory}, recursive: {recursive}")
    except Exception as e:
        log.warning(f"Error reading directory {directory} {e}")
    return all_files


def parse_plot_info(memo: bytes) -> tuple[Union[G1Element, bytes32], G1Element, PrivateKey]:
    # Parses the plot info bytes into keys
    if len(memo) == (48 + 48 + 32):
        # This is a public key memo
        return (
            G1Element.from_bytes(memo[:48]),
            G1Element.from_bytes(memo[48:96]),
            PrivateKey.from_bytes(memo[96:]),
        )
    elif len(memo) == (32 + 48 + 32):
        # This is a pool_contract_puzzle_hash memo
        return (
            bytes32(memo[:32]),

Review comment (performance):
I think this is quite slow. maybe that's fine for now. We'll probably have 6 months for optimizations between the 3.0 release and activation. An alternative would be to use the glob pattern `*.plot?`

Code after:
            config["harvester"]["parallel_decompressor_count"] = parallel_decompressor_count
        if decompressor_thread_count is not None:
            config["harvester"]["decompressor_thread_count"] = decompressor_thread_count
        if recursive_plot_scan is not None:
            config["harvester"]["recursive_plot_scan"] = recursive_plot_scan
        if refresh_parameter is not None:
            config["harvester"]["plots_refresh_parameter"] = refresh_parameter.to_json_dict()

        save_config(root_path, "config.yaml", config)


def get_filenames(directory: Path, recursive: bool, follow_links: bool) -> list[Path]:
    try:
        if not directory.exists():
            log.warning(f"Directory: {directory} does not exist.")
            return []
    except OSError as e:
        log.warning(f"Error checking if directory {directory} exists: {e}")
        return []
    all_files: list[Path] = []
    try:
        if follow_links and recursive:
            import glob

            v1_file_strs = glob.glob(str(directory / "**" / "*.plot"), recursive=True)
            v2_file_strs = glob.glob(str(directory / "**" / "*.plot2"), recursive=True)

            for file in v1_file_strs + v2_file_strs:
                filepath = Path(file).resolve()
                if filepath.is_file() and not filepath.name.startswith("._"):
                    all_files.append(filepath)
        else:
            glob_function = directory.rglob if recursive else directory.glob
            v1_files: list[Path] = [
                child for child in glob_function("*.plot") if child.is_file() and not child.name.startswith("._")
            ]
            v2_files: list[Path] = [
                child for child in glob_function("*.plot2") if child.is_file() and not child.name.startswith("._")
            ]
            all_files = v1_files + v2_files
        log.debug(f"get_filenames: {len(all_files)} files found in {directory}, recursive: {recursive}")
    except Exception as e:
        log.warning(f"Error reading directory {directory} {e}")
    return all_files


def parse_plot_info(memo: bytes) -> tuple[Union[G1Element, bytes32], G1Element, PrivateKey]:
    # Parses the plot info bytes into keys
    if len(memo) == (48 + 48 + 32):
        # This is a public key memo
        return (