changeset 1884:0614862a20ec beta

Added number of comments in changelog for each changeset - significantly improved speed of changelog page for large repos
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 11 Jan 2012 17:59:15 +0200
parents 69d3c4450944
children 350d95dece6f
files rhodecode/controllers/changelog.py rhodecode/lib/helpers.py rhodecode/model/db.py rhodecode/public/css/style.css rhodecode/templates/changelog/changelog.html
diffstat 5 files changed, 52 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/changelog.py	Tue Jan 10 07:01:12 2012 +0200
+++ b/rhodecode/controllers/changelog.py	Wed Jan 11 17:59:15 2012 +0200
@@ -38,6 +38,7 @@
 from rhodecode.lib.compat import json
 
 from vcs.exceptions import RepositoryError, ChangesetDoesNotExistError
+from rhodecode.model.db import Repository
 
 log = logging.getLogger(__name__)
 
@@ -75,12 +76,15 @@
                                                     branch_name=branch_name)]
                 c.total_cs = len(collection)
             else:
-                collection = list(c.rhodecode_repo)
+                collection = c.rhodecode_repo
                 c.total_cs = len(c.rhodecode_repo)
 
-
             c.pagination = RepoPage(collection, page=p, item_count=c.total_cs,
                                     items_per_page=c.size, branch=branch_name)
+            collection = list(c.pagination)
+            page_revisions = [x.raw_id for x in collection]
+            c.comments = c.rhodecode_db_repo.comments(page_revisions)
+
         except (RepositoryError, ChangesetDoesNotExistError, Exception), e:
             log.error(traceback.format_exc())
             h.flash(str(e), category='warning')
@@ -89,9 +93,8 @@
         self._graph(c.rhodecode_repo, collection, c.total_cs, c.size, p)
 
         c.branch_name = branch_name
-        c.branch_filters = [('',_('All Branches'))] + \
-            [(k,k) for k in c.rhodecode_repo.branches.keys()]
-
+        c.branch_filters = [('', _('All Branches'))] + \
+            [(k, k) for k in c.rhodecode_repo.branches.keys()]
 
         return render('changelog/changelog.html')
 
@@ -112,25 +115,16 @@
             c.jsdata = json.dumps([])
             return
 
-        revcount = min(repo_size, size)
-        offset = 1 if p == 1 else  ((p - 1) * revcount + 1)
-        try:
-            rev_end = collection.index(collection[(-1 * offset)])
-        except IndexError:
-            rev_end = collection.index(collection[-1])
-        rev_start = max(0, rev_end - revcount)
-
         data = []
-        rev_end += 1
+        revs = [x.revision for x in collection]
 
         if repo.alias == 'git':
-            for _ in xrange(rev_start, rev_end):
+            for _ in revs:
                 vtx = [0, 1]
                 edges = [[0, 0, 1]]
                 data.append(['', vtx, edges])
 
         elif repo.alias == 'hg':
-            revs = list(reversed(xrange(rev_start, rev_end)))
             c.dag = graphmod.colored(graphmod.dagwalker(repo._repo, revs))
             for (id, type, ctx, vtx, edges) in c.dag:
                 if type != graphmod.CHANGESET:
--- a/rhodecode/lib/helpers.py	Tue Jan 10 07:01:12 2012 +0200
+++ b/rhodecode/lib/helpers.py	Wed Jan 11 17:59:15 2012 +0200
@@ -607,7 +607,6 @@
 
             self.items = list(self.collection[self.first_item:self.last_item + 1])
 
-
             # Links to previous and next page
             if self.page > self.first_page:
                 self.previous_page = self.page - 1
@@ -791,8 +790,6 @@
         log.error(traceback.format_exc())
         pass
 
-    
-
     return text_
 
 
--- a/rhodecode/model/db.py	Tue Jan 10 07:01:12 2012 +0200
+++ b/rhodecode/model/db.py	Wed Jan 11 17:59:15 2012 +0200
@@ -27,6 +27,7 @@
 import logging
 import datetime
 import traceback
+from collections import defaultdict
 
 from sqlalchemy import *
 from sqlalchemy.ext.hybrid import hybrid_property
@@ -609,6 +610,22 @@
     def last_change(self):
         return self.scm_instance.last_change
 
+    def comments(self, revisions=None):
+        """
+        Returns comments for this repository grouped by revisions
+
+        :param revisions: filter query by revisions only
+        """
+        cmts = ChangesetComment.query()\
+            .filter(ChangesetComment.repo == self)
+        if revisions:
+            cmts = cmts.filter(ChangesetComment.revision.in_(revisions))
+        grouped = defaultdict(list)
+        for cmt in cmts.all():
+            grouped[cmt.revision].append(cmt)
+        return grouped
+
+
     #==========================================================================
     # SCM CACHE INSTANCE
     #==========================================================================
@@ -1044,7 +1061,7 @@
         return Session.query(User)\
                 .filter(cls.revision == revision)\
                 .join(ChangesetComment.author).all()
-
+    
 
 class Notification(Base, BaseModel):
     __tablename__ = 'notifications'
--- a/rhodecode/public/css/style.css	Tue Jan 10 07:01:12 2012 +0200
+++ b/rhodecode/public/css/style.css	Wed Jan 11 17:59:15 2012 +0200
@@ -2279,7 +2279,7 @@
 
 #graph_content .container {
 	border-bottom: 1px solid #DDD;
-	height: 55px;
+	height: 57px;
 	overflow: hidden;
 }
 
@@ -2330,8 +2330,20 @@
 	font-weight: bold !important;
 }
 
-
-.right div {
+.right .comments-container{
+	padding-right: 5px;
+	margin-top:1px;
+	float:right;
+	height:16px;
+}
+
+.right .comments-cnt{
+    float: left;
+    color: rgb(136, 136, 136); 
+    padding-right: 2px; 
+}
+
+.right .changes{
 	clear: both;
 }
 
@@ -2386,6 +2398,7 @@
 
 .right .parent {
 	color: #666666;
+	clear:both;
 }
 .right .logtags{
 	padding: 2px 2px 2px 2px;
--- a/rhodecode/templates/changelog/changelog.html	Tue Jan 10 07:01:12 2012 +0200
+++ b/rhodecode/templates/changelog/changelog.html	Wed Jan 11 17:59:15 2012 +0200
@@ -64,8 +64,14 @@
 						</div>	
 						<div class="right">
 									<div id="${cs.raw_id}_changes_info" class="changes">
-                                        <span id="${cs.raw_id}" class="changed_total tooltip" title="${_('Affected number of files, click to show more details')}">${len(cs.affected_files)}</span>
-									</div>					
+                                        <div id="${cs.raw_id}"  style="float:right;" class="changed_total tooltip" title="${_('Affected number of files, click to show more details')}">${len(cs.affected_files)}</div>
+                                        <div class="comments-container">
+                                        %if len(c.comments.get(cs.raw_id,[])) > 0:
+                                            <div class="comments-cnt" title="${('comments')}">${len(c.comments.get(cs.raw_id,[]))}</div>
+                                            <img src="${h.url('/images/icons/comments.png')}">
+                                        %endif    
+                                        </div>
+									</div>
 								   %if cs.parents:
 									%for p_cs in reversed(cs.parents):
 										<div class="parent">${_('Parent')}