Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-17465 Dashboard/XPathTable #3738

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the core problem. I don't know why XPathTable had its own StringId cache.

}
}
Loading