Limit concurrent thumbnail downloads to 8

This commit is contained in:
miruka 2019-07-18 20:49:47 -04:00
parent 9decd58992
commit 329c34cf94

View File

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