]> git.ipfire.org Git - pbs.git/commitdiff
builders: Make handling log messages actually fast
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 3 May 2025 11:39:09 +0000 (11:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 3 May 2025 11:39:09 +0000 (11:39 +0000)
We don't need to fetch the build object here which saves us from opening
and closing an entire database session which is not really needed.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/web/builders.py

index afcecee25a529696e49479505e375c7bff93f5ea..ea7f1e70715a7f085e396390e93414990e569848 100644 (file)
@@ -53,10 +53,6 @@ class APIv1ControlHandler(base.APIMixin, base.BackendMixin, tornado.websocket.We
                self.builder.disconnected()
 
        async def on_message(self, message):
-               # Fetch the builder again, because this is being executed as a separate task
-               # and therefore we cannot use the object from the previous session.
-               builder = await self.backend.builders.get_by_name(self.builder.name)
-
                # Decode message
                message = self._decode_json_message(message)
 
@@ -68,8 +64,12 @@ class APIv1ControlHandler(base.APIMixin, base.BackendMixin, tornado.websocket.We
                if type == "log":
                        return self.backend.logstreams.log(message)
 
+               # Fetch the builder again, because this is being executed as a separate task
+               # and therefore we cannot use the object from the previous session.
+               builder = await self.backend.builders.get_by_name(self.builder.name)
+
                # Handle stats
-               elif type == "stats":
+               if type == "stats":
                        async with await self.db.transaction():
                                await builder.log_stats(**data)