Skip to content
This repository
Browse code

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...
commit 98780652f0259e9dbd48ee02082e7bb549fe1e96 1 parent c9279a4
Antonio Salazar Cardozo Shadowfiend authored
28 web/webkit/src/main/scala/net/liftweb/http/js/ScriptRenderer.scala
@@ -46,6 +46,7 @@ object ScriptRenderer {
46 46 toSend.onSuccess = theSuccess;
47 47 toSend.onFailure = theFailure;
48 48 toSend.responseType = responseType;
  49 + toSend.version = liftAjax.lift_ajaxVersion++;
49 50
50 51 if (liftAjax.lift_uriSuffix) {
51 52 theData += '&' + liftAjax.lift_uriSuffix;
@@ -108,7 +109,8 @@ object ScriptRenderer {
108 109 },
109 110
110 111 lift_registerGC: function() {
111   - var data = "__lift__GC=_"
  112 + var data = "__lift__GC=_",
  113 + version = null;
112 114 """ + LiftRules.jsArtifacts.ajax(AjaxInfo(JE.JsRaw("data"),
113 115 "POST",
114 116 LiftRules.ajaxPostTimeout,
@@ -166,8 +168,10 @@ object ScriptRenderer {
166 168 aboutToSend.responseType.toLowerCase() === "json") {
167 169 liftAjax.lift_actualJSONCall(aboutToSend.theData, successFunc, failureFunc);
168 170 } else {
169   - var theData = aboutToSend.theData;
170   - liftAjax.lift_actualAjaxCall(theData, successFunc, failureFunc);
  171 + var theData = aboutToSend.theData,
  172 + version = aboutToSend.version;
  173 +
  174 + liftAjax.lift_actualAjaxCall(theData, version, successFunc, failureFunc);
171 175 }
172 176 }
173 177 }
@@ -181,17 +185,22 @@ object ScriptRenderer {
181 185 setTimeout("liftAjax.lift_doAjaxCycle();", 200);
182 186 },
183 187
184   - addPageName: function(url) {
185   - return """ + {
186   - if (LiftRules.enableLiftGC) {
187   - "url.replace('" + LiftRules.ajaxPath + "', '" + LiftRules.ajaxPath + "/'+lift_page);"
  188 + lift_ajaxVersion: 0,
  189 +
  190 + addPageNameAndVersion: function(url, version) {
  191 + """ + {
  192 + if (LiftRules.enableLiftGC) { """
  193 + var replacement = '""" + LiftRules.ajaxPath + """/'+lift_page;
  194 + if (version)
  195 + replacement += ('-'+(version%36).toString(36)) + (liftAjax.lift_ajaxQueue.length > 35 ? 35 : liftAjax.lift_ajaxQueue.length).toString(36);
  196 + return url.replace('""" + LiftRules.ajaxPath + """', replacement);"""
188 197 } else {
189   - "url;"
  198 + "return url;"
190 199 }
191 200 } + """
192 201 },
193 202
194   - lift_actualAjaxCall: function(data, onSuccess, onFailure) {
  203 + lift_actualAjaxCall: function(data, version, onSuccess, onFailure) {
195 204 """ +
196 205 LiftRules.jsArtifacts.ajax(AjaxInfo(JE.JsRaw("data"),
197 206 "POST",
@@ -202,6 +211,7 @@ object ScriptRenderer {
202 211 },
203 212
204 213 lift_actualJSONCall: function(data, onSuccess, onFailure) {
  214 + var version = null;
205 215 """ +
206 216 LiftRules.jsArtifacts.ajax(AjaxInfo(JE.JsRaw("data"),
207 217 "POST",
2  web/webkit/src/main/scala/net/liftweb/http/js/jquery/JQueryArtifacts.scala
@@ -97,7 +97,7 @@ trait JQueryArtifacts extends JSArtifacts {
97 97 def ajax(data: AjaxInfo): String = {
98 98 "jQuery.ajax(" + toJson(data, S.contextPath,
99 99 prefix =>
100   - JsRaw("liftAjax.addPageName(" + S.encodeURL(prefix + "/" + LiftRules.ajaxPath + "/").encJs + ")")) + ");"
  100 + JsRaw("liftAjax.addPageNameAndVersion(" + S.encodeURL(prefix + "/" + LiftRules.ajaxPath + "/").encJs + ", version)")) + ");"
101 101 }
102 102
103 103 /**

0 comments on commit 9878065

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