Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

changed clearing of the cache to clear for all user exercises

Summary: Changes needed for review K86121

Test Plan: Added to that review

Reviewers: kamens

Reviewed By: kamens

Differential Revision: http://phabricator.khanacademy.org/D933
  • Loading branch information...
commit ebfcd748ac100731a0abd2c93bb50f6c14f31eea 1 parent 1947b31
@tzjames tzjames authored
Showing with 12 additions and 34 deletions.
  1. +12 −34 khan-exercise.js
View
46 khan-exercise.js
@@ -290,6 +290,16 @@ var Khan = (function() {
})();
}
+ // If there are any requests left in the queue when the window unloads
+ // then we will have permanently lost their answers and will need to
+ // clear the session cache, to make sure we don't override what is
+ // passed down from the servers
+ $(window).unload(function() {
+ if(requestQueue["attempt_hint_queue"].queue().length) {
+ $(Khan).trigger("attemptError");
+ }
+ });
+
// The main Khan Module
var Khan = {
modules: {},
@@ -2117,57 +2127,25 @@ var Khan = (function() {
var data = buildAttemptData(pass, ++attempts, JSON.stringify(guess), curTime);
debugLog("attempt " + JSON.stringify(data));
- // Saving the current state of problems done before the attempt so
- // that it is stored in a closure and we can rely on resetting to
- // this current state if an error is thrown on page exit.
- var curTotalDone = pass === true ? problemNum : problemNum - 1;
-
request("problems/" + problemNum + "/attempt", data, function() {
// TODO: Save locally if offline
$(Khan).trigger("attemptSaved");
}, function(xhr) {
+ // Alert any listeners of the error before reload
+ $(Khan).trigger("attemptError");
if (xhr && xhr.readyState == 0) {
// This path gets called when there is a broken pipe during
// page unload- browser navigating away during ajax request
// See http://stackoverflow.com/questions/1370322/jquery-ajax-fires-error-callback-on-window-unload
-
- if(requestQueue["attempt_hint_queue"].queue().length > 1) {
- // if there are other requests left in the request
- // queue then they will not ever execute and the user's
- // work is lost. In order to avoid problem out of order
- // when the page is reloaded we need to reset the
- // totalDone in the SessionStorage to what it would
- // have been when this request finishes executing.
- //
- // If we run into problems with resetting the cache
- // in the future we can instead do
- // $(Khan).trigger("attemptError", userExercise);
- // which will clear the cache. This would not fix the
- // case of users hitting the back button, which would
- // cause the cache to be reverted to what it was when
- // the page initially loaded and cause out of order
- // errors.
- //
- // If in the future people complain about problems
- // being lost we could consider doing a
- // window.onbeforeunload = function (e) {
- // return 'Problems are being saved. Are you sure?';
- // };
- userExercise.totalDone = curTotalDone;
- $(Khan).trigger("attemptAborted", userExercise);
- }
return;
}
// Error during submit. Disable the page and ask users to
// reload in an attempt to get updated data.
- // Alert any listeners of the error before reload
- $(Khan).trigger("attemptError", userExercise);
-
// Hide the page so users don't continue
$("#problem-and-answer").css("visibility", "hidden");

4 comments on commit ebfcd74

@saasmath

This change breaks all exercises in "testmode" on line 297 with a reference error: $ is not defined.

jQuery is not yet loaded when this call is made.

--Gary

@xymostech
Owner

@saasmath We know, someone's fixing that

@saasmath

@xymostech I have applied the patch D944 from sandcastle and it seems to address this issue.

I would give the feedback to the Khan Academy team that if you are going to have an open-source project that is welcoming to outside participation (and I have participated in several), it is not OK to have a broken master branch for close to a week. Obviously, Thanksgiving weekend is an exceptional situation, but making a commit without testing prior to such an absence is something that I think is important to avoid.

--Gary

@xymostech
Owner

@saasmath Unfortunately, our duty is to improving and maintaining our website, khanacademy.org. I'm not sure if you noticed, but the exercises on that website have worked fine for the last week, even though the testing portion of the exercises (i.e. this repository) haven't been working. We are a small group of developers, and sometimes we don't do as much testing as we should, so we're sorry if we break things, but we do it all in the name of improving the education we provide through our website.

Please sign in to comment.
Something went wrong with that request. Please try again.