From a11c16d17b837adaa6cdea69970342d681d7600c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 12 Sep 2023 06:36:02 +0000 Subject: [PATCH] more asyncification for webdav --- api/advent22_api/core/webdav.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/api/advent22_api/core/webdav.py b/api/advent22_api/core/webdav.py index 5904c74..979554a 100644 --- a/api/advent22_api/core/webdav.py +++ b/api/advent22_api/core/webdav.py @@ -1,3 +1,4 @@ +import asyncio import re from io import BytesIO @@ -29,7 +30,12 @@ class WebDAV: Liste aller Dateien im Ordner `directory`, die zur RegEx `regex` passen """ - ls = cls._webdav_client.list(directory) + loop = asyncio.get_running_loop() + ls = await loop.run_in_executor( + None, + cls._webdav_client.list, + directory, + ) return [f"{directory}/{path}" for path in ls if regex.search(path)] @@ -40,7 +46,12 @@ class WebDAV: `True`, wenn an Pfad `path` eine Datei existiert """ - return cls._webdav_client.check(path) + loop = asyncio.get_running_loop() + return await loop.run_in_executor( + None, + cls._webdav_client.check, + path, + ) @classmethod @(_rb_ttl := AsyncTTL(time_to_live=SETTINGS.webdav.cache_ttl, skip_args=1)) @@ -50,7 +61,12 @@ class WebDAV: """ buffer = BytesIO() - cls._webdav_client.resource(path).write_to(buffer) + loop = asyncio.get_running_loop() + await loop.run_in_executor( + None, + cls._webdav_client.resource(path).write_to, + buffer, + ) buffer.seek(0) return buffer.read() @@ -69,7 +85,12 @@ class WebDAV: Bytes `buffer` in Datei in Pfad `path` schreiben """ - cls._webdav_client.resource(path).read_from(buffer) + loop = asyncio.get_running_loop() + await loop.run_in_executor( + None, + cls._webdav_client.resource(path).read_from, + buffer, + ) try: # hack: zugehörigen Cache-Eintrag entfernen