Skip to content
Browse files

Encode an AJAX request version in the request URI.

The AJAX request version has two components: the actual version number
and a count of queued requests. This is presented as two base-36 values
after a dash. So a request now looks like:

/ajax_request/F<page version>-v8

Where v indicates request number 31 and 8 indicates that there are 8
queued requests that have not been handled yet.
  • Loading branch information...
1 parent c9279a4 commit 98780652f0259e9dbd48ee02082e7bb549fe1e96 @Shadowfiend Shadowfiend committed Sep 24, 2012
View
28 web/webkit/src/main/scala/net/liftweb/http/js/ScriptRenderer.scala
@@ -46,6 +46,7 @@ object ScriptRenderer {
toSend.onSuccess = theSuccess;
toSend.onFailure = theFailure;
toSend.responseType = responseType;
+ toSend.version = liftAjax.lift_ajaxVersion++;
if (liftAjax.lift_uriSuffix) {
theData += '&' + liftAjax.lift_uriSuffix;
@@ -108,7 +109,8 @@ object ScriptRenderer {
},
lift_registerGC: function() {
- var data = "__lift__GC=_"
+ var data = "__lift__GC=_",
+ version = null;
""" + LiftRules.jsArtifacts.ajax(AjaxInfo(JE.JsRaw("data"),
"POST",
LiftRules.ajaxPostTimeout,
@@ -166,8 +168,10 @@ object ScriptRenderer {
aboutToSend.responseType.toLowerCase() === "json") {
liftAjax.lift_actualJSONCall(aboutToSend.theData, successFunc, failureFunc);
} else {
- var theData = aboutToSend.theData;
- liftAjax.lift_actualAjaxCall(theData, successFunc, failureFunc);
+ var theData = aboutToSend.theData,
+ version = aboutToSend.version;
+
+ liftAjax.lift_actualAjaxCall(theData, version, successFunc, failureFunc);
}
}
}
@@ -181,17 +185,22 @@ object ScriptRenderer {
setTimeout("liftAjax.lift_doAjaxCycle();", 200);
},
- addPageName: function(url) {
- return """ + {
- if (LiftRules.enableLiftGC) {
- "url.replace('" + LiftRules.ajaxPath + "', '" + LiftRules.ajaxPath + "/'+lift_page);"
+ lift_ajaxVersion: 0,
+
+ addPageNameAndVersion: function(url, version) {
+ """ + {
+ if (LiftRules.enableLiftGC) { """
+ var replacement = '""" + LiftRules.ajaxPath + """/'+lift_page;
+ if (version)
+ replacement += ('-'+(version%36).toString(36)) + (liftAjax.lift_ajaxQueue.length > 35 ? 35 : liftAjax.lift_ajaxQueue.length).toString(36);
+ return url.replace('""" + LiftRules.ajaxPath + """', replacement);"""
} else {
- "url;"
+ "return url;"
}
} + """
},
- lift_actualAjaxCall: function(data, onSuccess, onFailure) {
+ lift_actualAjaxCall: function(data, version, onSuccess, onFailure) {
""" +
LiftRules.jsArtifacts.ajax(AjaxInfo(JE.JsRaw("data"),
"POST",
@@ -202,6 +211,7 @@ object ScriptRenderer {
},
lift_actualJSONCall: function(data, onSuccess, onFailure) {
+ var version = null;
""" +
LiftRules.jsArtifacts.ajax(AjaxInfo(JE.JsRaw("data"),
"POST",
View
2 web/webkit/src/main/scala/net/liftweb/http/js/jquery/JQueryArtifacts.scala
@@ -97,7 +97,7 @@ trait JQueryArtifacts extends JSArtifacts {
def ajax(data: AjaxInfo): String = {
"jQuery.ajax(" + toJson(data, S.contextPath,
prefix =>
- JsRaw("liftAjax.addPageName(" + S.encodeURL(prefix + "/" + LiftRules.ajaxPath + "/").encJs + ")")) + ");"
+ JsRaw("liftAjax.addPageNameAndVersion(" + S.encodeURL(prefix + "/" + LiftRules.ajaxPath + "/").encJs + ", version)")) + ");"
}
/**

0 comments on commit 9878065

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