Remove encodings from "locales" table + delete incorrect locales
The frontend always stripped off the encodings already, so no point in
keeping that in the DB indices. The full locale was extracted from the
filename, which we still keep, so no information is list.
SQL "migration" script:
BEGIN;
CREATE INDEX files_tmp_locale ON files (locale);
INSERT INTO locales (locale) VALUES ('pl_PL'), ('is_IS'), ('ko_KR');
WITH obs(id, locale, lang) AS (
SELECT id, locale, regexp_replace(locale, '^([^.]+)\..+$', '\1') FROM locales WHERE locale LIKE '%.%'
UNION ALL
SELECT id, locale, '' FROM locales WHERE locale LIKE 'node%' OR locale = 'common'
), rep(old, new) AS (
SELECT o.id, x.id FROM obs o LEFT JOIN locales x ON x.locale = o.lang
), upd AS (
UPDATE files SET locale = new FROM rep WHERE locale = old
) DELETE FROM locales WHERE id IN(SELECT id FROM obs);
DROP INDEX files_tmp_locale;
COMMIT;
This commit is contained in:
parent
1ee5c9c2df
commit
cd5d2c6a20
3 changed files with 12 additions and 11 deletions
17
www/index.pl
17
www/index.pl
|
|
@ -199,13 +199,13 @@ sub man_pref_name {
|
|||
|
||||
sub man_languages {
|
||||
my($name, $sect) = @_;
|
||||
[ map $_->{lang}, tuwf->dbAlli(
|
||||
"SELECT DISTINCT substring(l.locale from '^[^.]+') AS lang
|
||||
[ map $_->{locale}, tuwf->dbAlli(
|
||||
"SELECT DISTINCT l.locale
|
||||
FROM files f
|
||||
JOIN mans m ON m.id = f.man
|
||||
JOIN locales l ON l.id = f.locale
|
||||
WHERE m.name =", \$name, 'AND m.section =', \$sect, "
|
||||
ORDER BY substring(l.locale from '^[^.]+') NULLS FIRST"
|
||||
ORDER BY l.locale"
|
||||
)->@* ];
|
||||
}
|
||||
|
||||
|
|
@ -741,9 +741,8 @@ sub man_nav_ {
|
|||
if(@$lang > 1) {
|
||||
b_ 'Languages';
|
||||
p_ sub {
|
||||
(my $cur = $man->{locale}||'') =~ s/\..*//;
|
||||
for (@$lang) {
|
||||
if(($_||'') eq $cur) {
|
||||
if(($_||'') eq $man->{locale}) {
|
||||
i_ $_ || 'default';
|
||||
} else {
|
||||
a_ href => $_ ? "/man.$_/$man->{name}.$man->{section}" : "/man/$man->{name}.$man->{section}", $_ || 'default';
|
||||
|
|
@ -894,7 +893,7 @@ TUWF::get qr{/(?<fmt>man|txt|raw)(?:\.(?<shorthash>[a-fA-F0-9]{8}))?(?:\.(?<lang
|
|||
push @where, sql 'v.version =', \$ver if length $ver;
|
||||
|
||||
push @where, sql 'f.shorthash =', \shorthash_to_int $shorthash if $shorthash;
|
||||
push @where, sql 'l.locale ilike', \(escape_like($lang).'%') if $lang;
|
||||
push @where, sql 'l.locale =', \$lang if $lang;
|
||||
|
||||
my($man, $section) = man_pref_name $name, sql_and @where;
|
||||
return tuwf->resNotFound if !$man;
|
||||
|
|
@ -1137,7 +1136,7 @@ TUWF::get qr{/loc/([a-fA-F0-9]{40})}, sub {
|
|||
TUWF::get qr{/ver(?:\.([a-fA-F0-9]{8}))?(?:\.([^/]+))?/([^/]+)\.([0-9a-zA-Z])}, sub {
|
||||
my($shorthash, $lang, $name, $sect) = tuwf->captures(1,2,3,4);
|
||||
$shorthash = $shorthash ? shorthash_to_int $shorthash : -1;
|
||||
($lang ||= '') =~ s/\..*//;
|
||||
$lang ||= '';
|
||||
|
||||
my $l = tuwf->dbAlli('
|
||||
SELECT p.system, p.name AS package, v.version, v.released, f.shorthash
|
||||
|
|
@ -1145,7 +1144,7 @@ TUWF::get qr{/ver(?:\.([a-fA-F0-9]{8}))?(?:\.([^/]+))?/([^/]+)\.([0-9a-zA-Z])},
|
|||
JOIN package_versions v ON v.id = f.pkgver
|
||||
JOIN packages p ON p.id = v.package
|
||||
WHERE f.man = (SELECT id FROM mans WHERE name =', \$name, 'AND section =', \$sect, ')
|
||||
AND f.locale IN(SELECT id FROM locales WHERE locale', $lang ? ('ILIKE', \(escape_like($lang).'%')) : ("= ''"), ')
|
||||
AND f.locale IN(SELECT id FROM locales WHERE locale =', \$lang, ')
|
||||
ORDER BY p.system DESC, p.name, v.released DESC, f.shorthash
|
||||
');
|
||||
|
||||
|
|
@ -1163,7 +1162,7 @@ TUWF::get qr{/ver(?:\.([a-fA-F0-9]{8}))?(?:\.([^/]+))?/([^/]+)\.([0-9a-zA-Z])},
|
|||
for (0..$#{$langs}) {
|
||||
txt_ ', ' if $_ > 0;
|
||||
if(($langs->[$_]||'') eq $lang) {
|
||||
i_ $langs->[$_] || 'default';
|
||||
b_ $langs->[$_] || 'default';
|
||||
} else {
|
||||
a_ href => '/ver'.($langs->[$_]?".$langs->[$_]":'')."/$name.$sect", $langs->[$_] || 'default';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue