]> git.ipfire.org Git - pbs.git/commitdiff
builds: Check if watchers exist before adding this
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 17 Feb 2025 11:44:02 +0000 (11:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 17 Feb 2025 11:44:02 +0000 (11:44 +0000)
There is no elegant way to upsert here, so this is what it has to be for
now.

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

index 4a57a1b76a93c1ec40a9c5f3327cb15d58ebecf7..ab518c350e909e71d57967c00c7f84aa7aa551d3 100644 (file)
@@ -698,6 +698,13 @@ class Build(database.Base, database.BackendMixin, database.SoftDeleteMixin):
                """
                        Adds a watcher to this build
                """
+               # Don't add the same watcher more than once
+               # SQLAlchemy does not have an elegant way to do an upsert here or to ignore
+               # and additional inserts, so we will have to check ourselves. Oh well.
+               if await self.watched_by(user):
+                       return
+
+               # Add the new watcher
                return await self.db.insert(
                        BuildWatcher,
                        build = self,