From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id cFHMDULOhWAfgQAAgWs5BA (envelope-from ) for ; Sun, 25 Apr 2021 22:17:06 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id AMeOCULOhWC2bwAA1q6Kng (envelope-from ) for ; Sun, 25 Apr 2021 20:17:06 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 9CBAE24DE8 for ; Sun, 25 Apr 2021 22:17:05 +0200 (CEST) Received: from localhost ([::1]:33294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lalBg-0005XI-It for larch@yhetil.org; Sun, 25 Apr 2021 16:17:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lalBP-0005LG-5v for guix-devel@gnu.org; Sun, 25 Apr 2021 16:16:47 -0400 Received: from mout01.posteo.de ([185.67.36.65]:43127) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lalBL-0002C9-SU for guix-devel@gnu.org; Sun, 25 Apr 2021 16:16:46 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 60047240027 for ; Sun, 25 Apr 2021 22:16:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1619381800; bh=Wnf9vpV+oyuuhEXBZsG5Q8l5Dm7Tnu0S0HAHdLyU6kI=; h=Date:From:To:Cc:Subject:From; b=CoEsaPeJ1zkqf9nGnmBzTIahdBI+lSZDi5BT7oNOAxrpo55qBzr6uzMSIWvRj9tsw yQXGuJQXMkfI8zZeHhCzsFXbeihtuKs8VM9ScF7h8nDsf7at3klNtNjkJzAWoL7EiW Yk6i7UDgIs9u+Xjb/bDVmrlnN1Z2fRKK+oE9Tc1Bt9CmueP1LkfMOnYtoeSfdM/I+z WrKVed3Z5xEpxKyIoy1dUiC8uaZUeZ2DFgKQBZQtsh3pwG/GYhvRLj0ftJrfOdH5Vw vVl1HRep1bFSo33qsIYqC0aeQLPR1q3THj9x8d9f3WohWZ0ghZM6AzhcO5nLQehfFh tgLQ8WIevW2ew== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4FSznd48Pfz9rxH; Sun, 25 Apr 2021 22:16:37 +0200 (CEST) Date: Sun, 25 Apr 2021 20:15:07 +0000 From: Luciana Lima Brito To: Christopher Baines Subject: Re: Outreachy - Guix Data Service: questions about improving the data for derivation comparisons. Message-ID: <20210425171507.6a259017@lubrito> In-Reply-To: <87bla4hdto.fsf@cbaines.net> References: <20210421152914.461bbdbb@lubrito> <87bla6iwli.fsf@cbaines.net> <20210422170040.37941083@lubrito> <875z0ehyl3.fsf@cbaines.net> <20210422180208.28473e41@lubrito> <87zgxqggw9.fsf@cbaines.net> <20210423181551.01c42455@lubrito> <87bla4hdto.fsf@cbaines.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/UrVsEkUORmRKccHt1B+YK6B" Received-SPF: pass client-ip=185.67.36.65; envelope-from=lubrito@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: guix-devel@gnu.org Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: "Guix-devel" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1619381825; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=dVs2l/iwVsYpr7iNsCLJjRu1W0jZHiVSdzEZachma0M=; b=ij6f7T1fTVRUBkSImb6ZGs+kA2ih/+9DF8Htakc4glOU6uw3adSXuI7Y/BJ/zwp+rnqZb9 ggIko0s9c3timET0CSaOhGXHUPo2vFE45sRY2iAshDZJic0UvdW5tn2mKzpKmUAfUbhr6O L5ffDEoGYUz8kWYENp0zCI7KZJrHesh9TZ7LInVaur5EjVuUxqHxRZ5Ecc562nFs5+6TDc GgTyYLjAFx35OKfxwSZpPUvXJH7MhqafYZJfVU73wHRbS3niNWsgGtXO9W4jLlQUM5Qs9T NoXji9lYbqltGMk105JnIQ7jgI9aKiRU+e1kvVTE0gaJPBjKGuxU2kQVqJsG5A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1619381825; a=rsa-sha256; cv=none; b=eahrQpy8CIveQYkA3CrkTbY3WWRmo2gc3vlXDd9GdaeA0N0TnBI0nM3qcEUwRACJg5fYTW GvOW7RJyCBQ78rnfUBSfdYD5HyJa+o3ZfljIeBJAp3ghnYL5ZvliVnWX1HA5fFSp+ASez9 h5ejktB1SnxXYMCJPRHn12X2uqyL0nYGdCr3cJ+u/8dusT4mdVKJvR7z+GDB7Ty8OkQGfq u3kGrLB2nXL3V0YMWm84IpR0UAgsXyKdhK97XoZAiCS9/pkvpAZP/0BmznrxEqU6wYqzJ/ l3c0HEE1PUy6RUwsDqcuAlsp0NedlJ0VLj+I1/4cLxOYN3e3462rEVwDFa5skw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=CoEsaPeJ; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of guix-devel-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-devel-bounces@gnu.org X-Migadu-Spam-Score: -2.65 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=CoEsaPeJ; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of guix-devel-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-devel-bounces@gnu.org X-Migadu-Queue-Id: 9CBAE24DE8 X-Spam-Score: -2.65 X-Migadu-Scanner: scn0.migadu.com X-TUID: kRc23n3T2NK/ --MP_/UrVsEkUORmRKccHt1B+YK6B Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi Your advices helped me think more clearly. There was no need to create or modify structures other than what I was already changing. I now return an alist instead of a list on the derivation-differences-* functions on comparison.scm (for outputs, inputs and sources). It helped to simplify the mapping on controller.scm. The changes on html.scm were minimal, basically it is matching on pairs, instead of single values. Two questions: 1 - The match on the html expects 5 values for "outputs", so I had to settle on using empty objects on the JSON, when needed, else it would break the match on the html. Is it ok? 2 - Now on controller.scm "outputs", "inputs", "sources", and even "arguments" have the same structure, which is an alist of the form: ((base . (...)) (target . (...)) (common . (...))) and I'm using the same map and match-lambda code to process them, wouldn't it be reasonable now to make it a local function? I'm sending the patch. I'll be waiting your reviews. -- Best Regards, Luciana Lima Brito MSc. in Computer Science --MP_/UrVsEkUORmRKccHt1B+YK6B Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-Change-handling-of-queried-data-for-derivations-comp.patch >From d605d519a684b1be57ebd09cdf697bcdba017da1 Mon Sep 17 00:00:00 2001 From: Luciana Brito Date: Sun, 25 Apr 2021 15:17:33 -0300 Subject: [PATCH] Change handling of queried data for derivations comparison. comparison.scm: return query data for derivation comparison as an alist, instead of list. html.scm: match on pairs, instead of single values. controller.scm: simplify mapping on outputs/inputs/sources. --- guix-data-service/comparison.scm | 68 +++++++++++--------- guix-data-service/web/compare/controller.scm | 62 ++++-------------- guix-data-service/web/compare/html.scm | 43 ++++++------- 3 files changed, 69 insertions(+), 104 deletions(-) diff --git a/guix-data-service/comparison.scm b/guix-data-service/comparison.scm index e5e1955..1f47c38 100644 --- a/guix-data-service/comparison.scm +++ b/guix-data-service/comparison.scm @@ -158,19 +158,23 @@ GROUP BY 1, 2, 3, 4, 5")) (let ((parsed-derivation-ids (map string->number (parse-postgresql-array-string derivation_ids)))) - (list output-name - path - hash-algorithm - hash - recursive - (append (if (memq base-derivation-id - parsed-derivation-ids) - '(base) - '()) - (if (memq target-derivation-id - parsed-derivation-ids) - '(target) - '())))))) + `((output-name . ,output-name) + (path . ,path) + ,@(if (string? hash-algorithm) + `((hash-algorithm . ,hash-algorithm)) + `((hash-algorithm . ()))) + ,@(if (string? hash) + `((hash . ,hash)) + `((hash . ()))) + (recursive . ,(string=? recursive "t")) + ,(append (if (memq base-derivation-id + parsed-derivation-ids) + '(base) + '()) + (if (memq target-derivation-id + parsed-derivation-ids) + '(target) + '())))))) (exec-query conn query))) (define (derivation-inputs-differences-data conn @@ -202,16 +206,16 @@ INNER JOIN derivations ON derivation_outputs.derivation_id = derivations.id (let ((parsed-derivation-ids (map string->number (parse-postgresql-array-string derivation_ids)))) - (list derivation_file_name - derivation_output_name - (append (if (memq base-derivation-id - parsed-derivation-ids) - '(base) - '()) - (if (memq target-derivation-id - parsed-derivation-ids) - '(target) - '())))))) + `((derivation_file_name . ,derivation_file_name) + (derivation_output_name . ,derivation_output_name) + ,(append (if (memq base-derivation-id + parsed-derivation-ids) + '(base) + '()) + (if (memq target-derivation-id + parsed-derivation-ids) + '(target) + '())))))) (exec-query conn query))) (define (derivation-sources-differences-data conn @@ -235,15 +239,15 @@ GROUP BY derivation_source_files.store_path")) (let ((parsed-derivation-ids (map string->number (parse-postgresql-array-string derivation_ids)))) - (list store_path - (append (if (memq base-derivation-id - parsed-derivation-ids) - '(base) - '()) - (if (memq target-derivation-id - parsed-derivation-ids) - '(target) - '())))))) + `((store_path . ,store_path) + ,(append (if (memq base-derivation-id + parsed-derivation-ids) + '(base) + '()) + (if (memq target-derivation-id + parsed-derivation-ids) + '(target) + '())))))) (exec-query conn query))) (define* (package-derivation-differences-data conn diff --git a/guix-data-service/web/compare/controller.scm b/guix-data-service/web/compare/controller.scm index 895bb40..9ef8e5b 100644 --- a/guix-data-service/web/compare/controller.scm +++ b/guix-data-service/web/compare/controller.scm @@ -590,60 +590,24 @@ ((application/json) (let ((outputs (map - (lambda (label items) - (cons label - (list->vector - (map - (match-lambda - ((name path hash-alg hash recursive) - `((name . ,name) - (path . ,path) - ,@(if (string? hash-alg) - `((hash-algorithm . ,hash-alg)) - '()) - ,@(if (string? hash) - `((hash . ,hash)) - '()) - (recursive . ,(string=? recursive "t"))))) - (or items '()))))) - '(base target common) - (let ((output-groups (assq-ref data 'outputs))) - (list (assq-ref output-groups 'base) - (assq-ref output-groups 'target) - (assq-ref output-groups 'common))))) + (match-lambda + ((label values ...) + `(,label . ,(list->vector values)))) + (assq-ref data 'outputs))) (inputs (map - (lambda (label items) - (cons label - (list->vector - (map - (match-lambda - ((derivation output) - `((derivation . ,derivation) - (output . ,output)))) - (or items '()))))) - '(base target common) - (let ((input-groups (assq-ref data 'inputs))) - (list (assq-ref input-groups 'base) - (assq-ref input-groups 'target) - (assq-ref input-groups 'common))))) + (match-lambda + ((label values ...) + `(,label . ,(list->vector values)))) + (assq-ref data 'inputs))) (sources (map - (lambda (label items) - (cons label - (list->vector - (map - (match-lambda - ((derivation) - `((derivation . ,derivation)))) - (or items '()))))) - '(base target common) - (let ((source-groups (assq-ref data 'sources))) - (list (assq-ref source-groups 'base) - (assq-ref source-groups 'target) - (assq-ref source-groups 'common))))) + (match-lambda + ((label values ...) + `(,label . ,(list->vector values)))) + (assq-ref data 'sources))) (arguments (map @@ -651,7 +615,7 @@ ((label args ...) `(,label . ,(list->vector args)))) (assq-ref data 'arguments)))) - + (render-json `((base . ((derivation . ,base-derivation))) (target . ((derivation . ,target-derivation))) diff --git a/guix-data-service/web/compare/html.scm b/guix-data-service/web/compare/html.scm index 5b5fe0a..30cc499 100644 --- a/guix-data-service/web/compare/html.scm +++ b/guix-data-service/web/compare/html.scm @@ -487,27 +487,24 @@ (th "Hash") (th "Recursive"))) (tbody - ,@(let ((base-outputs (assq-ref outputs 'base)) - (target-outputs (assq-ref outputs 'target)) - (common-outputs (assq-ref outputs 'common))) - (append-map - (lambda (label items) - (map - (match-lambda - ((name path hash-algorithm hash recursive) - `(tr - (td ,label) - (td ,name) - (td (a (@ (href ,path)) - ,(display-store-item path))) - (td ,hash-algorithm) - (td ,hash) - (td ,recursive)))) - (or items '()))) - (list base target "Common") - (list (assq-ref outputs 'base) - (assq-ref outputs 'target) - (assq-ref outputs 'common)))))))) + ,@(append-map + (lambda (label items) + (map + (match-lambda + (((_ . name) (_ . path) (_ . hash-alg) (_ . hash) (_ . recursive)) + `(tr + (td ,label) + (td ,name) + (td (a (@ (href ,path)) + ,(display-store-item path))) + (td ,hash-alg) + (td ,hash) + (td ,recursive)))) + (or items '()))) + (list base target "Common") + (list (assq-ref outputs 'base) + (assq-ref outputs 'target) + (assq-ref outputs 'common))))))) (h2 "Inputs") ,@(let ((inputs (assq-ref data 'inputs))) `((table @@ -522,7 +519,7 @@ (lambda (label items) (map (match-lambda - ((derivation outputs) + (((_ . derivation) (_ . outputs)) `(tr (td ,label) (td (a (@ (href ,derivation)) @@ -546,7 +543,7 @@ (lambda (label items) (map (match-lambda - ((file) + (((_ . file)) `(tr (td ,label) (td (a (@ (href ,file)) -- 2.30.2 --MP_/UrVsEkUORmRKccHt1B+YK6B--