Skip to contentSkip to conversation

Prevent stale data in ToasterTables

PATCH In review Elliot Smith 2 participants 5 messages Oct 1, 2015 – Oct 6, 2015

lore
Share & tools
lore
#0 lore raw

v2 cover Prevent stale data in ToasterTables

Prevent incorrect caching of ToasterTable data so it doesn't go stale as the user navigates browser history with back/forward.

v2: Remove code to push and pop context data into the browser history, as we now just make fresh requests to the server instead.

Changes since poky-contrib/toaster-next @ 97e5625bb7b8f8de8fda0fb4dd188bf107a5f4fa are in:
git://git.yoctoproject.org/poky-contrib, elliot/toaster/bad_caching-7660
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=elliot/toaster/bad_caching-7660

Related bug: https://bugzilla.yoctoproject.org/show_bug.cgi?id=7660

Elliot Smith (3):
toaster: Don't add new history entries when table data loads
toaster: Don't HTTP cache ToasterTable responses
toaster: Don't store table data in the browser

 bitbake/lib/toaster/toastergui/static/js/table.js | 12 ------------
 bitbake/lib/toaster/toastergui/widgets.py         |  6 ++++++
 2 files changed, 6 insertions(+), 12 deletions(-)

--
Elliot Smith
Software Engineer
Intel OTC

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

#1 lore raw

PATCH v2 1/3 toaster: Don't add new history entries when table data loads

When ToasterTable data is loaded into the UI, a new entry is added to the browser history. This means that pressing the back button appears to have no effect, as you end up at the same page, possibly with slightly different data.

Instead, use replaceState(), so that the browser history doesn't grow, but the page context still gets updated.

[YOCTO #7660]

---
 bitbake/lib/toaster/toastergui/static/js/table.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/toaster/toastergui/static/js/table.js +1 -1
index f18034d..99b99a0 100644
@@ -49,7 +49,7 @@ function tableInit(ctx){
         headers: { 'X-CSRFToken' : $.cookie('csrftoken')},
         success: function(tableData) {
           updateTable(tableData);
-          window.history.pushState({
+          window.history.replaceState({
               tableData: tableData,
               tableParams: tableParams
           }, null, libtoaster.dumpsUrlParams(tableParams));
Signature · 14 lines
Elliot Smith
Software Engineer
Intel OTC

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
#2 lore raw

PATCH v2 2/3 toaster: Don't HTTP cache ToasterTable responses

In reply to Elliot Smith

Django allows generated pages to be cached by default by the browser. This can result in stale data displaying for some pages.

Instead, disable HTTP caching of ToasterTable responses, so that each time a ToasterTable view is displayed, its data is refreshed. This carries a performance penalty, but ensures that ToasterTable views (e.g. compatible layers) are correctly refreshed if the user navigates their history with forward/back.

[YOCTO #7660]

---
 bitbake/lib/toaster/toastergui/widgets.py | 6 ++++++
 1 file changed, 6 insertions(+)
bitbake/lib/toaster/toastergui/widgets.py +6 -0
index e58dd7c..6bb3889 100644
@@ -20,6 +20,7 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 from django.views.generic import View, TemplateView
+from django.views.decorators.cache import cache_control
 from django.shortcuts import HttpResponse
 from django.http import HttpResponseBadRequest
 from django.core import serializers
@@ -64,6 +65,11 @@ class ToasterTable(TemplateView):
                         orderable=True,
                         field_name="id")
 
+        # prevent HTTP caching of table data
+    @cache_control(must_revalidate=True, max_age=0, no_store=True, no_cache=True)
+    def dispatch(self, *args, **kwargs):
+        return super(ToasterTable, self).dispatch(*args, **kwargs)
+
     def get_context_data(self, **kwargs):
         context = super(ToasterTable, self).get_context_data(**kwargs)
         context['title'] = self.title
Signature · 14 lines
Elliot Smith
Software Engineer
Intel OTC

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
#3 lore raw

PATCH v2 3/3 toaster: Don't store table data in the browser

In reply to Elliot Smith

As table data is no longer loaded from the history stack (it's refreshed from the server on navigation), remove the onpopstate event handler and the code which pushes the page data onto the stack.

[YOCTO #7660]

---
 bitbake/lib/toaster/toastergui/static/js/table.js | 12 ------------
 1 file changed, 12 deletions(-)
bitbake/lib/toaster/toastergui/static/js/table.js +0 -12
index 99b99a0..b30b552 100644
@@ -33,14 +33,6 @@ function tableInit(ctx){
 
   loadData(tableParams);
 
-  window.onpopstate = function(event){
-    if (event.state){
-      tableParams = event.state.tableParams;
-      /* We skip loadData and just update the table */
-      updateTable(event.state.tableData);
-    }
-  };
-
   function loadData(tableParams){
     $.ajax({
         type: "GET",
@@ -49,10 +41,6 @@ function tableInit(ctx){
         headers: { 'X-CSRFToken' : $.cookie('csrftoken')},
         success: function(tableData) {
           updateTable(tableData);
-          window.history.replaceState({
-              tableData: tableData,
-              tableParams: tableParams
-          }, null, libtoaster.dumpsUrlParams(tableParams));
         }
     });
   }
Signature · 14 lines
Elliot Smith
Software Engineer
Intel OTC

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
#4 lore raw

Re: [review-request][PATCH 3/3] toaster: Don't store table data in the browser

Just for the record this patch set was submitted upstream (I updated the wrong thread)

Michael

Quoted 42 lines · Elliot Smith

As table data is no longer loaded from the history stack (it's refreshed from the server on navigation), remove the onpopstate event handler and the code which pushes the page data onto the stack.

[YOCTO #7660]

---
  bitbake/lib/toaster/toastergui/static/js/table.js | 12 ------------
  1 file changed, 12 deletions(-)
bitbake/lib/toaster/toastergui/static/js/table.js +0 -12
index 99b99a0..b30b552 100644
@@ -33,14 +33,6 @@ function tableInit(ctx){
 
    loadData(tableParams);
 
-  window.onpopstate = function(event){
-    if (event.state){
-      tableParams = event.state.tableParams;
-      /* We skip loadData and just update the table */
-      updateTable(event.state.tableData);
-    }
-  };
-
    function loadData(tableParams){
      $.ajax({
          type: "GET",
@@ -49,10 +41,6 @@ function tableInit(ctx){
          headers: { 'X-CSRFToken' : $.cookie('csrftoken')},
          success: function(tableData) {
            updateTable(tableData);
-          window.history.replaceState({
-              tableData: tableData,
-              tableParams: tableParams
-          }, null, libtoaster.dumpsUrlParams(tableParams));
          }
      });
    }