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-16900 Avoid 304 Not Modified; instead use boolean json.unchanged #3597

Merged
merged 1 commit into from
Apr 3, 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
18 changes: 5 additions & 13 deletions tools/cldr-apps/js/src/esm/cldrAnnounce.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions tools/cldr-apps/js/test/run.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<Announcement> 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<Announcement> announcementList = new ArrayList<>();
AnnouncementData.get(user, announcementList);
announcements = announcementList.toArray(new Announcement[0]);
}
}
}

Expand Down
Loading