[damned-lies] Fixed caching of branch stats depending on user



commit 8044d041acb7b706e8ddd62e6e0fcca1cdb2edd3
Author: Claude Paroz <claude 2xlibre net>
Date:   Fri Oct 2 10:04:24 2015 +0200

    Fixed caching of branch stats depending on user

 stats/views.py |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/stats/views.py b/stats/views.py
index 244d0ae..04472b0 100644
--- a/stats/views.py
+++ b/stats/views.py
@@ -47,13 +47,15 @@ def modules(request, format='html'):
     }
     return render(request, 'module_list.html', context)
 
+
 def module(request, module_name):
     mod = get_object_or_404(Module, name=module_name)
-    branches = mod.get_branches()
+    branches = sorted(mod.branch_set.all())
     if request.user.is_authenticated():
         person = Person.get_by_user(request.user)
         langs = person.get_languages()
-        for branch in branches:
+        for branch in branches[:2]:
+            # Cache the two first branch stats with user langs included
             branch.get_ui_stats(mandatory_langs=langs)
             branch.get_doc_stats(mandatory_langs=langs)
 
@@ -68,16 +70,25 @@ def module(request, module_name):
     }
     return render(request, 'module_detail.html', context)
 
+
 def module_branch(request, module_name, branch_name):
     """ This view is used to dynamically load a specific branch stats (jquery.load) """
     mod = get_object_or_404(Module, name=module_name)
     branch = mod.branch_set.get(name=branch_name)
+    if request.user.is_authenticated():
+        person = Person.get_by_user(request.user)
+        langs = person.get_languages()
+        # Cache the branch stats with user langs included
+        branch.get_ui_stats(mandatory_langs=langs)
+        branch.get_doc_stats(mandatory_langs=langs)
+
     context = {
         'module': mod,
         'branch': branch,
     }
     return render(request, 'branch_detail.html', context)
 
+
 @login_required
 def module_edit_branches(request, module_name):
     mod = get_object_or_404(Module, name=module_name)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]