Skip to content

Commit

Permalink
CLDR-17465 Dashboard/XPathTable (unicode-org#3738)
Browse files Browse the repository at this point in the history
  • Loading branch information
srl295 authored May 21, 2024
1 parent 2f9cdc2 commit 4bfec42
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
21 changes: 18 additions & 3 deletions tools/cldr-apps/js/src/esm/cldrDash.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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…`);

Expand All @@ -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,
Expand Down
25 changes: 3 additions & 22 deletions tools/cldr-apps/src/main/java/org/unicode/cldr/web/XPathTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ private void setupDB(Connection ourConn) throws SQLException {

public Hashtable<String, Integer> stringToId =
new Hashtable<>(4096); // public for statistics only
public Hashtable<Long, String> sidToString =
new Hashtable<>(4096); // public for statistics only

public String statistics() {
return "DB: "
Expand Down Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 4bfec42

Please sign in to comment.