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 Shorten server response if unchanged; bug fix, refactor #3596

Merged
merged 1 commit into from
Apr 2, 2024

Conversation

btangmu
Copy link
Member

@btangmu btangmu commented Apr 2, 2024

-Refactor (encapsulate) to calculate unread/total counts in only one place; new callbackSetCounts

-On front end, remember the last announcement ID fetched (alreadyGotId)

-On back end, respond with 304 Not Modified if alreadyGotId matches

-Do not report 304 Not Modified response as error; log it to console only if debugging enabled

-New front-end method resetSchedule prevents delay and prevents 304 response

-Format Test.html (not specific to this ticket; unrelated PR left it unformatted)

-Comments

CLDR-16900

  • This PR completes the ticket.

ALLOW_MANY_COMMITS=true

-Refactor (encapsulate) to calculate unread/total counts in only one place; new callbackSetCounts

-On front end, remember the last announcement ID fetched (alreadyGotId)

-On back end, respond with 304 Not Modified if alreadyGotId matches

-Do not report 304 Not Modified response as error; log it to console only if debugging enabled

-New front-end method resetSchedule prevents delay and prevents 304 response

-Format Test.html (not specific to this ticket; unrelated PR left it unformatted)

-Comments
@btangmu btangmu self-assigned this Apr 2, 2024
@btangmu btangmu requested a review from srl295 April 2, 2024 16:18
@@ -119,6 +149,7 @@ async function compose(formState, viewCallbackComposeResult) {
}

async function saveCheckmark(checked, announcement) {
resetSchedule();
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 fixes a bug -- otherwise, the "unread" number by the balloon icon in the main menu took 60 seconds before it updated in response to adding a checkmark for "I have read this"

if (!callbackSetData) {
// The Announcements page was just opened, so re-fetch the data immediately regardless
// of how recently it was fetched previously (for unread count)
schedule.reset();
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 schedule.reset isn't needed here anymore since now AnnouncePanel.vue "created" method calls cldrAnnounce.resetSchedule

}

function handleErrorOrNotModified(e) {
if (e.message === "Not Modified") {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (e.message === "Not Modified") {
if (e.status === 304) {

should be able to check the status code directly - the message can be variable.

Copy link
Member Author

Choose a reason for hiding this comment

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

That would require changes to cldrAjax -- currently cldrAjax.handleFetchErrors is as follows:

function handleFetchErrors(response) {
  if (!response.ok) {
    throw new Error(response.statusText);
  }
  return response;
}

The Error only contains response.statusText -- I'm not sure how to set e.status in a standard way

@@ -71,6 +76,9 @@ public Response getAnnouncements(@HeaderParam(Auth.SESSION_HEADER) String sessio
if (SurveyMain.isBusted() || !SurveyMain.wasInitCalled() || !SurveyMain.triedToStartUp()) {
return STError.surveyNotQuiteReady();
}
if (alreadyGotId != 0 && alreadyGotId == AnnouncementData.getMostRecentAnnouncementId()) {
return Response.notModified().build();
Copy link
Member Author

Choose a reason for hiding this comment

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

I have some doubt whether this is a standard way to use notModified (304)...

Possible alternatives include (1) setting headers so that the browser delivers cached response for 304 (but that's maybe less efficient -- needless work processing the identical json); (2) return 200 and short json, e.g., just json.unchanged = true; (3) Etag...

Comment on lines +79 to +81
if (alreadyGotId != 0 && alreadyGotId == AnnouncementData.getMostRecentAnnouncementId()) {
return Response.notModified().build();
}
Copy link
Member

@srl295 srl295 Apr 2, 2024

Choose a reason for hiding this comment

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

might consider adding this here (see entry for 503, etc in the annotations on this function)

    @APIResponse(responseCode = "304", description = "No further announcements (past alreadyGotId"),

Copy link
Member Author

Choose a reason for hiding this comment

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

good idea

if tests pass, maybe best to merge this as-is since it does include bug fix and performance improvement; but keep ticket open and consider protocol improvements under discussion

Copy link
Member

@srl295 srl295 left a comment

Choose a reason for hiding this comment

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

nice

@btangmu btangmu merged commit ef93a34 into unicode-org:main Apr 2, 2024
11 checks passed
@btangmu btangmu deleted the t16900_d branch April 2, 2024 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants