From: Michael Tremer Date: Wed, 5 Feb 2025 16:20:19 +0000 (+0000) Subject: messages: Fetch messages in badges X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2f57edae707d81cbefcebda47c4191c4d851e401;p=pbs.git messages: Fetch messages in badges We would have otherwise looped for forever since we cannot check in advance whether the iterator actually has any elements, but we don't want to connect to the mail relay if there is literally nothing to send. So as a compromise we fetch messages in batches. Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/messages.py b/src/buildservice/messages.py index 796ffa40..7fabab54 100644 --- a/src/buildservice/messages.py +++ b/src/buildservice/messages.py @@ -230,7 +230,7 @@ class Queue(base.Object): """ Queues and delivers any emails """ - def get_messages(self, limit=None): + async def get_messages(self, limit=None): stmt = ( sqlalchemy .select( @@ -246,7 +246,7 @@ class Queue(base.Object): .limit(limit) ) - return self.db.fetch(stmt) + return await self.db.fetch_as_list(stmt) async def enqueue(self, message, priority=0): """ @@ -285,7 +285,7 @@ class Queue(base.Object): async with self._send_lock: while True: - messages = self.get_messages() + messages = await self.get_messages(limit=10) # If there are no messages left, we can quit if not messages: