async def _list_all_drive_items_recursively(
        self,
        client: httpx.AsyncClient,
        drive_id: str,
    ) -> AsyncGenerator[Dict, None]:
        """Recursively list all items in a drive using BFS approach."""
        # Queue of folder IDs to process (None = root folder)
        folder_queue = deque([None])
        processed_folders = set()  # Avoid infinite loops

        while folder_queue:
            current_folder_id = folder_queue.popleft()

            # Skip if we've already processed this folder
            if current_folder_id in processed_folders:
                continue
            processed_folders.add(current_folder_id)

            try:
                async for item in self._list_drive_items(client, drive_id, current_folder_id):
                    yield item

                    # If this item is a folder, add it to the queue for processing
                    if "folder" in item and len(folder_queue) < 100:  # Limit queue size
                        folder_queue.append(item["id"])
            except Exception as e:
                logger.error(f"Error processing folder {current_folder_id}: {e}")
                continue
Recursively list all items in a drive using BFS approach.
backend/airweave/platform/sources/onedrive.py