diff --git a/tools/cldr-apps/js/src/esm/cldrAnnounce.mjs b/tools/cldr-apps/js/src/esm/cldrAnnounce.mjs index 7e9e2f9ce10..52a53887643 100644 --- a/tools/cldr-apps/js/src/esm/cldrAnnounce.mjs +++ b/tools/cldr-apps/js/src/esm/cldrAnnounce.mjs @@ -82,23 +82,15 @@ async function refresh(viewCallbackSetData, viewCallbackSetCounts) { .then(cldrAjax.handleFetchErrors) .then((r) => r.json()) .then(setPosts) - .catch(handleErrorOrNotModified); -} - -function handleErrorOrNotModified(e) { - if (e.message === "Not Modified") { - // 304 - if (CLDR_ANNOUNCE_DEBUG) { - console.log("cldrAnnounce got " + e.message); - } - } else { - console.error(e); - } + .catch(console.error); } function setPosts(json) { - thePosts = json; schedule.setResponseTime(); + if (json.unchanged) { + return; + } + thePosts = json; setAlreadyGotId(thePosts); const totalCount = thePosts.announcements?.length || 0; let checkedCount = 0; diff --git a/tools/cldr-apps/js/test/run.sh b/tools/cldr-apps/js/test/run.sh new file mode 100644 index 00000000000..c774e16e683 --- /dev/null +++ b/tools/cldr-apps/js/test/run.sh @@ -0,0 +1,8 @@ +# This needs to be run from the cldr folder +# Optionally, to run this as cldrtestjs, you may have in .bash_profile: +# alias cldrtestjs='cd [path/to/cldr] && sh tools/cldr-apps/js-unittest/run.sh' +cd tools/cldr-apps/js +npm install +npm run build-test +cd ../../.. +npx open-cli tools/cldr-apps/js/test/Test.html diff --git a/tools/cldr-apps/src/main/java/org/unicode/cldr/web/api/Announcements.java b/tools/cldr-apps/src/main/java/org/unicode/cldr/web/api/Announcements.java index 7e56caa7aba..2301fa37880 100644 --- a/tools/cldr-apps/src/main/java/org/unicode/cldr/web/api/Announcements.java +++ b/tools/cldr-apps/src/main/java/org/unicode/cldr/web/api/Announcements.java @@ -76,22 +76,29 @@ public Response getAnnouncements( if (SurveyMain.isBusted() || !SurveyMain.wasInitCalled() || !SurveyMain.triedToStartUp()) { return STError.surveyNotQuiteReady(); } - if (alreadyGotId != 0 && alreadyGotId == AnnouncementData.getMostRecentAnnouncementId()) { - return Response.notModified().build(); - } - AnnouncementResponse response = new AnnouncementResponse(session.user); + Boolean unchanged = + (alreadyGotId != 0 + && alreadyGotId == AnnouncementData.getMostRecentAnnouncementId()); + AnnouncementResponse response = new AnnouncementResponse(session.user, unchanged); return Response.ok(response).build(); } @Schema(description = "List of announcements") public static final class AnnouncementResponse { + @Schema(description = "unchanged") + public boolean unchanged; + @Schema(description = "announcements") public Announcement[] announcements; - public AnnouncementResponse(UserRegistry.User user) { - List announcementList = new ArrayList<>(); - AnnouncementData.get(user, announcementList); - announcements = announcementList.toArray(new Announcement[0]); + public AnnouncementResponse(UserRegistry.User user, Boolean unchanged) { + this.unchanged = unchanged; + + if (!unchanged) { + List announcementList = new ArrayList<>(); + AnnouncementData.get(user, announcementList); + announcements = announcementList.toArray(new Announcement[0]); + } } }