aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix-data-service/model/package-metadata.scm71
-rw-r--r--guix-data-service/model/package.scm66
-rw-r--r--guix-data-service/web/revision/controller.scm33
-rw-r--r--guix-data-service/web/revision/html.scm7
4 files changed, 158 insertions, 19 deletions
diff --git a/guix-data-service/model/package-metadata.scm b/guix-data-service/model/package-metadata.scm
index 6180274..e753dea 100644
--- a/guix-data-service/model/package-metadata.scm
+++ b/guix-data-service/model/package-metadata.scm
@@ -30,7 +30,9 @@
#:use-module (guix-data-service model location)
#:use-module (guix-data-service model utils)
#:export (select-package-metadata-by-revision-name-and-version
- inferior-packages->package-metadata-ids))
+ inferior-packages->package-metadata-ids
+
+ package-description-and-synopsis-locale-options-guix-revision))
(define locales
'("cs_CZ.utf8"
@@ -101,9 +103,9 @@
" AND ")))
(define (select-package-metadata-by-revision-name-and-version
- conn revision-commit-hash name version)
+ conn revision-commit-hash name version locale)
(define query "
-SELECT package_metadata.synopsis, package_metadata.description,
+SELECT translated_package_synopsis.synopsis, translated_package_descriptions.description,
package_metadata.home_page,
locations.file, locations.line, locations.column_number,
(SELECT JSON_AGG((license_data.*))
@@ -120,6 +122,42 @@ INNER JOIN packages
ON package_metadata.id = packages.package_metadata_id
LEFT OUTER JOIN locations
ON package_metadata.location_id = locations.id
+INNER JOIN (
+ SELECT DISTINCT ON (package_description_sets.id) package_description_sets.id, package_descriptions.description
+ FROM package_descriptions
+ INNER JOIN package_description_sets
+ ON package_descriptions.id = ANY (package_description_sets.description_ids)
+ INNER JOIN package_metadata
+ ON package_metadata.package_description_set_id = package_description_sets.id
+ INNER JOIN packages
+ ON packages.package_metadata_id = package_metadata.id
+ AND packages.name = $2
+ AND packages.version = $3
+ ORDER BY package_description_sets.id,
+ CASE WHEN package_descriptions.locale = $4 THEN 2
+ WHEN package_descriptions.locale = 'en_US.utf8' THEN 1
+ ELSE 0
+ END DESC
+) AS translated_package_descriptions
+ ON package_metadata.package_description_set_id = translated_package_descriptions.id
+INNER JOIN (
+ SELECT DISTINCT ON (package_synopsis_sets.id) package_synopsis_sets.id, package_synopsis.synopsis
+ FROM package_synopsis
+ INNER JOIN package_synopsis_sets
+ ON package_synopsis.id = ANY (package_synopsis_sets.synopsis_ids)
+ INNER JOIN package_metadata
+ ON package_metadata.package_synopsis_set_id = package_synopsis_sets.id
+ INNER JOIN packages
+ ON packages.package_metadata_id = package_metadata.id
+ AND packages.name = $2
+ AND packages.version = $3
+ ORDER BY package_synopsis_sets.id,
+ CASE WHEN package_synopsis.locale = $4 THEN 2
+ WHEN package_synopsis.locale = 'en_US.utf8' THEN 1
+ ELSE 0
+ END DESC
+) AS translated_package_synopsis
+ ON package_metadata.package_synopsis_set_id = translated_package_synopsis.id
WHERE packages.id IN (
SELECT package_derivations.package_id
FROM package_derivations
@@ -141,7 +179,7 @@ WHERE packages.id IN (
(if (string-null? license-json)
#()
(json-string->scm license-json)))))
- (exec-query conn query (list revision-commit-hash name version))))
+ (exec-query conn query (list revision-commit-hash name version locale))))
(define (insert-package-metadata metadata-rows)
(string-append "INSERT INTO package_metadata "
@@ -167,7 +205,7 @@ WHERE packages.id IN (
(define (inferior-packages->translated-package-descriptions-and-synopsis inferior
inferior-package-id)
- (define (translate inferior-package-id)
+ (define (translate inferior-package)
`(let* ((package (hashv-ref %package-table ,inferior-package-id))
(source-locale "en_US.utf8")
(source-synopsis
@@ -366,3 +404,26 @@ WHERE packages.id IN (
;; There is so much package metadata that it's worth creating a temporary
;; table
#:use-temporary-table? #t))
+
+(define (package-description-and-synopsis-locale-options-guix-revision conn
+ revision-id)
+ (exec-query
+ conn
+ "SELECT DISTINCT coalesce(package_descriptions.locale, package_synopsis.locale)
+ FROM package_descriptions
+ INNER JOIN package_description_sets
+ ON package_descriptions.id = ANY (package_description_sets.description_ids)
+ INNER JOIN package_metadata
+ ON package_metadata.package_description_set_id = package_description_sets.id
+ INNER JOIN package_synopsis_sets
+ ON package_synopsis_sets.id = package_metadata.package_synopsis_set_id
+ INNER JOIN package_synopsis
+ ON package_synopsis.id = ANY (package_synopsis_sets.synopsis_ids)
+ INNER JOIN packages
+ ON packages.package_metadata_id = package_metadata.id
+ INNER JOIN package_derivations
+ ON package_derivations.package_id = packages.id
+ INNER JOIN guix_revision_package_derivations
+ ON package_derivations.id = guix_revision_package_derivations.package_derivation_id
+ WHERE guix_revision_package_derivations.revision_id = $1"
+ (list revision-id)))
diff --git a/guix-data-service/model/package.scm b/guix-data-service/model/package.scm
index 01ba65a..42c4e83 100644
--- a/guix-data-service/model/package.scm
+++ b/guix-data-service/model/package.scm
@@ -53,12 +53,13 @@
(define* (select-packages-in-revision conn commit-hash
#:key limit-results
- after-name)
+ after-name
+ locale)
(define query
(string-append "
WITH data AS (
- SELECT packages.name, packages.version, package_metadata.synopsis,
- package_metadata.description, package_metadata.home_page,
+ SELECT packages.name, packages.version, translated_package_synopsis.synopsis,
+ translated_package_descriptions.description, package_metadata.home_page,
locations.file, locations.line, locations.column_number,
(SELECT JSON_AGG((license_data.*))
FROM (
@@ -74,6 +75,32 @@ WITH data AS (
ON packages.package_metadata_id = package_metadata.id
LEFT OUTER JOIN locations
ON package_metadata.location_id = locations.id
+ INNER JOIN (
+ SELECT DISTINCT ON (package_synopsis_sets.id) package_synopsis_sets.id,
+ package_synopsis.synopsis
+ FROM package_synopsis_sets
+ INNER JOIN package_synopsis
+ ON package_synopsis.id = ANY (package_synopsis_sets.synopsis_ids)
+ ORDER BY package_synopsis_sets.id,
+ CASE WHEN package_synopsis.locale = $2 THEN 2
+ WHEN package_synopsis.locale = 'en_US.utf8' THEN 1
+ ELSE 0
+ END DESC
+ ) AS translated_package_synopsis
+ ON package_metadata.package_synopsis_set_id = translated_package_synopsis.id
+ INNER JOIN (
+ SELECT DISTINCT ON (package_description_sets.id) package_description_sets.id,
+ package_descriptions.description
+ FROM package_description_sets
+ INNER JOIN package_descriptions
+ ON package_descriptions.id = ANY (package_description_sets.description_ids)
+ ORDER BY package_description_sets.id,
+ CASE WHEN package_descriptions.locale = $2 THEN 2
+ WHEN package_descriptions.locale = 'en_US.utf8' THEN 1
+ ELSE 0
+ END DESC
+ ) AS translated_package_descriptions
+ ON package_metadata.package_description_set_id = translated_package_descriptions.id
WHERE packages.id IN (
SELECT package_derivations.package_id
FROM package_derivations
@@ -88,7 +115,7 @@ WITH data AS (
SELECT DISTINCT name
FROM data"
(if after-name
- "\nWHERE name > $2\n"
+ "\nWHERE name > $3\n"
"")
" ORDER BY name"
(if limit-results
@@ -101,6 +128,7 @@ WHERE data.name IN (SELECT name FROM package_names);"))
(exec-query conn query
`(,commit-hash
+ ,locale
,@(if after-name
(list after-name)
'()))))
@@ -113,8 +141,8 @@ WHERE data.name IN (SELECT name FROM package_names);"))
"
SELECT packages.name,
packages.version,
- package_metadata.synopsis,
- package_metadata.description,
+ translated_package_synopsis.synopsis,
+ translated_package_descriptions.description,
package_metadata.home_page,
locations.file, locations.line, locations.column_number,
(SELECT JSON_AGG((license_data.*))
@@ -131,6 +159,32 @@ INNER JOIN package_metadata
ON packages.package_metadata_id = package_metadata.id
LEFT OUTER JOIN locations
ON package_metadata.location_id = locations.id
+INNER JOIN (
+ SELECT DISTINCT ON (package_synopsis_sets.id) package_synopsis_sets.id,
+ package_synopsis.synopsis
+ FROM package_synopsis_sets
+ INNER JOIN package_synopsis
+ ON package_synopsis.id = ANY (package_synopsis_sets.synopsis_ids)
+ ORDER BY package_synopsis_sets.id,
+ CASE WHEN package_synopsis.locale = $2 THEN 2
+ WHEN package_synopsis.locale = 'en_US.utf8' THEN 1
+ ELSE 0
+ END DESC
+) AS translated_package_synopsis
+ ON package_metadata.package_synopsis_set_id = translated_package_synopsis.id
+INNER JOIN (
+ SELECT DISTINCT ON (package_description_sets.id) package_description_sets.id,
+ package_descriptions.description
+ FROM package_description_sets
+ INNER JOIN package_descriptions
+ ON package_descriptions.id = ANY (package_description_sets.description_ids)
+ ORDER BY package_description_sets.id,
+ CASE WHEN package_descriptions.locale = $2 THEN 2
+ WHEN package_descriptions.locale = 'en_US.utf8' THEN 1
+ ELSE 0
+ END DESC
+) AS translated_package_descriptions
+ ON package_metadata.package_description_set_id = translated_package_descriptions.id
WHERE packages.id IN (
SELECT package_derivations.package_id
FROM package_derivations
diff --git a/guix-data-service/web/revision/controller.scm b/guix-data-service/web/revision/controller.scm
index d4a5e83..6fa225f 100644
--- a/guix-data-service/web/revision/controller.scm
+++ b/guix-data-service/web/revision/controller.scm
@@ -125,7 +125,8 @@
(guard-against-mutually-exclusive-query-parameters
(parse-query-parameters
request
- `((after_name ,identity)
+ `((locale ,identity #:default "en_US.utf8")
+ (after_name ,identity)
(field ,identity #:multi-value
#:default ("version" "synopsis"))
(search_query ,identity)
@@ -535,6 +536,14 @@
`("Revision " (samp ,commit-hash)))
(header-link
(string-append "/revision/" commit-hash)))
+ (define description-and-synopsis-locale-options
+ (map
+ (match-lambda
+ ((locale)
+ locale))
+ (package-description-and-synopsis-locale-options-guix-revision
+ conn (commit->revision-id conn commit-hash))))
+
(if (any-invalid-query-parameters? query-parameters)
(case (most-appropriate-mime-type
'(application/json text/html)
@@ -549,6 +558,7 @@
'()
'()
#f
+ #f
#:path-base path-base
#:header-text header-text
#:header-link header-link))))
@@ -568,7 +578,8 @@
conn
commit-hash
#:limit-results limit-results
- #:after-name (assq-ref query-parameters 'after_name))))
+ #:after-name (assq-ref query-parameters 'after_name)
+ #:locale (assq-ref query-parameters 'locale))))
(git-repositories
(git-repositories-containing-commit conn
commit-hash))
@@ -625,6 +636,7 @@
packages
git-repositories
show-next-page?
+ description-and-synopsis-locale-options
#:path-base path-base
#:header-text header-text
#:header-link header-link)
@@ -682,19 +694,25 @@
"/revision/" commit-hash))
version-history-link)
- (define lint-warnings-locale-options
+ (define locale-options
(map
(match-lambda
((locale)
locale))
- (lint-warning-message-locales-for-revision conn commit-hash)))
+ (delete-duplicates
+ (append
+ (package-description-and-synopsis-locale-options-guix-revision
+ conn (commit->revision-id conn commit-hash))
+ (lint-warning-message-locales-for-revision conn commit-hash)))))
- (let* ((metadata
+ (let* ((locale (assq-ref query-parameters 'locale))
+ (metadata
(select-package-metadata-by-revision-name-and-version
conn
commit-hash
name
- version))
+ version
+ locale))
(derivations
(select-derivations-by-revision-name-and-version
conn
@@ -704,7 +722,6 @@
(git-repositories
(git-repositories-containing-commit conn
commit-hash))
- (locale (assq-ref query-parameters 'locale))
(lint-warnings
(select-lint-warnings-by-revision-package-name-and-version
conn
@@ -742,7 +759,7 @@
git-repositories
lint-warnings
query-parameters
- lint-warnings-locale-options
+ locale-options
#:header-text header-text
#:header-link header-link
#:version-history-link
diff --git a/guix-data-service/web/revision/html.scm b/guix-data-service/web/revision/html.scm
index 4485b77..b7a2ad8 100644
--- a/guix-data-service/web/revision/html.scm
+++ b/guix-data-service/web/revision/html.scm
@@ -519,6 +519,7 @@
packages
git-repositories
show-next-page?
+ locale-options
#:key path-base
header-text header-link)
(define field-options
@@ -554,6 +555,12 @@
(style "padding-bottom: 0")
(class "form-horizontal"))
,(form-horizontal-control
+ "Locale" query-parameters
+ #:options locale-options
+ #:allow-selecting-multiple-options #f
+ #:help-text
+ "Language.")
+ ,(form-horizontal-control
"Search query" query-parameters
#:help-text
"List packages where the name or synopsis match the query.")