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
|
|
@ -37,7 +37,7 @@ pub fn parse_path(path: &str) -> Option<(&str, &str, &str)> {
|
|||
let section = cap.get(3).unwrap().as_str();
|
||||
|
||||
// Some weird directories that happen to match the locale
|
||||
if locale.contains("openmpi") || locale.contains("mpich") || locale.contains("mvapich") {
|
||||
if locale.contains("openmpi") || locale.contains("mpich") || locale.contains("mvapich") || locale.starts_with("nodejs") {
|
||||
locale = "";
|
||||
}
|
||||
|
||||
|
|
@ -59,6 +59,7 @@ pub fn parse_path(path: &str) -> Option<(&str, &str, &str)> {
|
|||
// Some more weird directories that happen to match the locale
|
||||
(n, s, "5man") |
|
||||
(n, s, "c") |
|
||||
(n, s, "common") |
|
||||
(n, s, "man") |
|
||||
(n, s, "man1") |
|
||||
(n, s, "man2") |
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ fn insert_pkg(tr: &mut postgres::Transaction, opt: &PkgOpt) -> Option<(i32,i32)>
|
|||
|
||||
fn insert_man_row<T: postgres::GenericClient>(tr: &mut T, verid: i32, path: &str, enc: &str, content: i32) {
|
||||
let (name, sect, locale) = man::parse_path(path).unwrap();
|
||||
let lang = locale.split_once('.').map(|x| x.0).unwrap_or(locale);
|
||||
let q = "WITH ms(id) AS (SELECT id FROM mans WHERE name = $2 AND section = $3),
|
||||
mi(id) AS (INSERT INTO mans (name, section) SELECT $2, $3 WHERE NOT EXISTS(SELECT 1 FROM ms) RETURNING id),
|
||||
m(id) AS (SELECT id FROM ms UNION SELECT id FROM mi),
|
||||
|
|
@ -110,7 +111,7 @@ fn insert_man_row<T: postgres::GenericClient>(tr: &mut T, verid: i32, path: &str
|
|||
c(shorthash) AS (SELECT hash_to_shorthash(hash) FROM contents WHERE id = $4)
|
||||
INSERT INTO files (pkgver, man, content, shorthash, locale, encoding, filename)
|
||||
SELECT $1, m.id, $4, c.shorthash, l.id, e.id, '/'||$7 FROM m, l, e, c";
|
||||
if let Err(e) = tr.execute(q, &[&verid, &name, §, &content, &locale, &enc, &path]) {
|
||||
if let Err(e) = tr.execute(q, &[&verid, &name, §, &content, &lang, &enc, &path]) {
|
||||
// I think this can only happen if archread gives us the same file twice, which really
|
||||
// shouldn't happen. But I'd rather continue with an error logged than panic.
|
||||
error!("Can't insert verid {} fn {}: {}", verid, path, e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue