From 6d2f1353df8c5d9b9dea4d6fb711cfcb738c5e8b Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Tue, 21 May 2024 17:12:48 -0500 Subject: [PATCH] CLDR-17465 Dashboard/XPathTable - remove duplicate StringId table within XPathTable - improve error messaging in cldrDash.mjs --- tools/cldr-apps/js/src/esm/cldrDash.mjs | 21 +++++++++++++--- .../java/org/unicode/cldr/web/XPathTable.java | 25 +++---------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/tools/cldr-apps/js/src/esm/cldrDash.mjs b/tools/cldr-apps/js/src/esm/cldrDash.mjs index fe4b1189aca..49e8356f9e6 100644 --- a/tools/cldr-apps/js/src/esm/cldrDash.mjs +++ b/tools/cldr-apps/js/src/esm/cldrDash.mjs @@ -396,14 +396,22 @@ async function downloadXlsx(data, locale, cb) { const xlsFileName = `Dash_${locale}_${coverageLevelName}.xlsx`; // Fetch all XPaths in parallel since it'll take a while - cb(`Loading…`); + cb(`Loading rows…`); const allXpaths = []; for (let dashEntry of entries) { if (dashEntry.section === "Reports") { continue; // skip this } allXpaths.push(dashEntry.xpstrid); + try { + await xpathMap.get(dashEntry.xpstrid); + } catch (e) { + throw Error( + `${e}: Could not load XPath for ${JSON.stringify(dashEntry)}` + ); + } } + cb(`Loading xpaths…`); await Promise.all(allXpaths.map((x) => xpathMap.get(x))); cb(`Calculating…`); @@ -427,8 +435,15 @@ async function downloadXlsx(data, locale, cb) { ]; for (let e of entries) { - const xpath = - e.section === "Reports" ? "-" : (await xpathMap.get(e.xpstrid)).path; + async function getXpath() { + if (e.section === "Reports") return "-"; + try { + return (await xpathMap.get(e.xpstrid)).path; + } catch (ex) { + throw Error(`${e}: Could not get xpath of ${JSON.stringify(e)}`); + } + } + const xpath = await getXpath(); const url = `https://st.unicode.org/cldr-apps/v#/${e.locale}/${e.page}/${e.xpstrid}`; ws_data.push([ e.cat, diff --git a/tools/cldr-apps/src/main/java/org/unicode/cldr/web/XPathTable.java b/tools/cldr-apps/src/main/java/org/unicode/cldr/web/XPathTable.java index 98317d8c62b..5bf26a477d4 100644 --- a/tools/cldr-apps/src/main/java/org/unicode/cldr/web/XPathTable.java +++ b/tools/cldr-apps/src/main/java/org/unicode/cldr/web/XPathTable.java @@ -150,8 +150,6 @@ private void setupDB(Connection ourConn) throws SQLException { public Hashtable stringToId = new Hashtable<>(4096); // public for statistics only - public Hashtable sidToString = - new Hashtable<>(4096); // public for statistics only public String statistics() { return "DB: " @@ -375,7 +373,7 @@ public final String getById(int id) { public final void setById(int id, String xpath) { xpath = xpath.intern(); stringToId.put(idToString_put(id, xpath), id); - sidToString.put(getStringID(xpath), xpath); + StringId.getId(xpath); // ensure in cache } /** @@ -758,24 +756,7 @@ public String getByStringID(String id) { } } - String getByStringID(long l) { - String s = sidToString.get(l); - if (s != null) return s; - // slow way - for (String x : stringToId.keySet()) { - if (getStringID(x) == l) { - sidToString.put(l, x); - return x; - } - } - if (SurveyMain.isUnofficial()) { - logger.warning( - "xpt: Couldn't find stringid " - + Long.toHexString(l) - + " - sid has " - + sidToString.size()); - } - // it may be - return null; + final String getByStringID(long l) { + return StringId.getStringFromId(l); } }