Limit concurrent thumbnail downloads to 8
This commit is contained in:
		| @@ -20,6 +20,8 @@ from nio.api import ResizingMethod | |||||||
| Size      = Tuple[int, int] | Size      = Tuple[int, int] | ||||||
| ImageData = Tuple[bytearray, Size, int]  # last int: pyotherside format enum | ImageData = Tuple[bytearray, Size, int]  # last int: pyotherside format enum | ||||||
|  |  | ||||||
|  | CONCURRENT_DOWNLOADS_LIMIT = asyncio.BoundedSemaphore(8) | ||||||
|  |  | ||||||
|  |  | ||||||
| @dataclass | @dataclass | ||||||
| class Thumbnail: | class Thumbnail: | ||||||
| @@ -85,13 +87,14 @@ class Thumbnail: | |||||||
|         ) |         ) | ||||||
|         parsed = urlparse(self.mxc) |         parsed = urlparse(self.mxc) | ||||||
|  |  | ||||||
|         response = await client.thumbnail( |         async with CONCURRENT_DOWNLOADS_LIMIT: | ||||||
|             server_name = parsed.netloc, |             response = await client.thumbnail( | ||||||
|             media_id    = parsed.path.lstrip("/"), |                 server_name = parsed.netloc, | ||||||
|             width       = self.server_size[0], |                 media_id    = parsed.path.lstrip("/"), | ||||||
|             height      = self.server_size[1], |                 width       = self.server_size[0], | ||||||
|             method      = self.resize_method, |                 height      = self.server_size[1], | ||||||
|         ) |                 method      = self.resize_method, | ||||||
|  |             ) | ||||||
|  |  | ||||||
|         if isinstance(response, nio.ThumbnailError): |         if isinstance(response, nio.ThumbnailError): | ||||||
|             # Return a transparent 1x1 PNG |             # Return a transparent 1x1 PNG | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	