guix-commits
[Top][All Lists]
Advanced

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

08/13: Rewrite part of insert-missing-data-and-return-all-ids to avoid f


From: Christopher Baines
Subject: 08/13: Rewrite part of insert-missing-data-and-return-all-ids to avoid filter
Date: Fri, 19 Jan 2024 04:57:47 -0500 (EST)

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

commit e51f87cc7ea0b38254a8b1a01c83c6b8f6173812
Author: Christopher Baines <mail@cbaines.net>
AuthorDate: Thu Jan 18 14:41:54 2024 +0000

    Rewrite part of insert-missing-data-and-return-all-ids to avoid filter
    
    As filter can use part of the input list, which then prevents modifying the
    filtered list.
---
 guix-data-service/model/utils.scm | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/guix-data-service/model/utils.scm 
b/guix-data-service/model/utils.scm
index b46e2e4..c05f20d 100644
--- a/guix-data-service/model/utils.scm
+++ b/guix-data-service/model/utils.scm
@@ -406,17 +406,24 @@ WHERE table_name = $1"
                               data)
                           3000)))))
          (missing-entries
-          (filter (lambda (field-values)
-                    (not (vhash-assoc
-                          ;; Normalise at this point, so that the proper value
-                          ;; to insert is carried forward
-                          (normalise-values field-values)
-                          existing-entries)))
-                  (if sets-of-data?
-                      (delete-duplicates* (concatenate data))
-                      (if delete-duplicates?
-                          (delete-duplicates* data)
-                          data))))
+          (let loop ((lst (if sets-of-data?
+                              (concatenate data)
+                              data))
+                     (result '()))
+            (if (null? lst)
+                (if delete-duplicates?
+                    (delete-duplicates* result)
+                    result)
+                (let ((field-values (car lst)))
+                  (if (vhash-assoc
+                       ;; Normalise at this point, so that the proper value
+                       ;; to insert is carried forward
+                       (normalise-values field-values)
+                       existing-entries)
+                      (loop (cdr lst)
+                            result)
+                      (loop (cdr lst)
+                            (cons field-values result)))))))
          (new-entries
           (if (null? missing-entries)
               '()



reply via email to

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