aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2024-11-29 13:48:10 +0000
committerChristopher Baines <mail@cbaines.net>2024-11-29 14:06:08 +0000
commit930169751ca748ee3a604a3942a05a1d1b28a7b6 (patch)
tree1a38534e874344c69f158900b1745f4d0ed947d5
parent9a38374e7c27e41f592f457c53e1b187b08b7d59 (diff)
downloaddata-service-930169751ca748ee3a604a3942a05a1d1b28a7b6.tar
data-service-930169751ca748ee3a604a3942a05a1d1b28a7b6.tar.gz
Handle conflicts when inserting lint warning message sets
-rw-r--r--guix-data-service/model/lint-warning-message.scm53
1 files 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