guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

05/18: Handle conflicts when inserting lint warning message sets


From: Christopher Baines
Subject: 05/18: Handle conflicts when inserting lint warning message sets
Date: Mon, 16 Dec 2024 04:02:40 -0500 (EST)

cbaines pushed a commit to branch master
in repository data-service.

commit 930169751ca748ee3a604a3942a05a1d1b28a7b6
Author: Christopher Baines <mail@cbaines.net>
AuthorDate: Fri Nov 29 13:48:10 2024 +0000

    Handle conflicts when inserting lint warning message sets
---
 guix-data-service/model/lint-warning-message.scm | 53 ++++++++++++------------
 1 file changed, 26 insertions(+), 27 deletions(-)

diff --git a/guix-data-service/model/lint-warning-message.scm 
b/guix-data-service/model/lint-warning-message.scm
index 72a8617..7dd0e28 100644
--- a/guix-data-service/model/lint-warning-message.scm
+++ b/guix-data-service/model/lint-warning-message.scm
@@ -35,22 +35,6 @@
            (list locale message)))
         messages-by-locale)))
 
-(define (insert-lint-warning-message-set conn lint-message-ids)
-  (let ((query
-         (string-append
-          "INSERT INTO lint_warning_message_sets (message_ids) VALUES "
-          (string-append
-           "('{"
-           (string-join
-            (map number->string
-                 (sort lint-message-ids <))
-            ", ")
-           "}')")
-          " RETURNING id")))
-
-    (match (exec-query conn query)
-      (((id)) id))))
-
 (define (lint-warning-message-data->lint-warning-message-set-id
          conn
          messages-by-locale)
@@ -58,21 +42,36 @@
   (let* ((lint-warning-message-ids
           (lint-warning-message-data->lint-warning-message-ids
            conn messages-by-locale))
-         (lint-message-set-id
-          (exec-query
-           conn
-           (string-append
-            "SELECT id FROM lint_warning_message_sets "
-            "WHERE message_ids = ARRAY["
-            (string-join (map number->string
-                              (sort lint-warning-message-ids <)) ", ")
-            "]"))))
+         (select-query
+          (string-append
+           "SELECT id FROM lint_warning_message_sets "
+           "WHERE message_ids = ARRAY["
+           (string-join (map number->string
+                             (sort lint-warning-message-ids <)) ", ")
+           "]")))
 
     (string->number
-     (match lint-message-set-id
+     (match (exec-query conn select-query)
        (((id)) id)
        (()
-        (insert-lint-warning-message-set conn lint-warning-message-ids))))))
+        (match (exec-query
+                conn
+                (string-append
+                 "
+INSERT INTO lint_warning_message_sets (message_ids) VALUES "
+                 (string-append
+                  "('{"
+                  (string-join
+                   (map number->string
+                        (sort lint-warning-message-ids <))
+                   ", ")
+                  "}')") "
+ON CONFLICT DO NOTHING RETURNING id"))
+            (((id)) id)
+            (()
+             (match (exec-query conn select-query)
+               (((id)) id)))))))))
+
 
 (define (lint-warning-message-locales-for-revision conn commit-hash)
   (exec-query



reply via email to

[Prev in Thread] Current Thread [Next in Thread]