Changeset - 0069657aaf42
[Not reviewed]
beta
0 3 1
Marcin Kuzminski - 14 years ago 2011-10-29 00:57:09
marcin@python-works.com
lazy load of branches and tags menu
- to reduce load on repositories with large amount of branches and tags.
- reduce load times of pages significantly on large repos
4 files changed with 107 insertions and 83 deletions:
0 comments (0 inline, 0 general)
rhodecode/config/routing.py
Show inline comments
 
@@ -62,6 +62,8 @@ def make_map(config):
 
    rmap.connect('home', '/', controller='home', action='index')
 
    rmap.connect('repo_switcher', '/repos', controller='home',
 
                 action='repo_switcher')
 
    rmap.connect('branch_tag_switcher', '/branches-tags/{repo_name:.*}', 
 
                 controller='home',action='branch_tag_switcher')    
 
    rmap.connect('bugtracker',
 
                 "http://bitbucket.org/marcinkuzminski/rhodecode/issues",
 
                 _static=True)
rhodecode/controllers/home.py
Show inline comments
 
@@ -58,3 +58,12 @@ class HomeController(BaseController):
 
            return render('/repo_switcher_list.html')
 
        else:
 
            return HTTPBadRequest()
 

	
 
    def branch_tag_switcher(self, repo_name):
 
        c.rhodecode_db_repo = Repository.get_by_repo_name(c.repo_name)
 
        c.rhodecode_repo = c.rhodecode_db_repo.scm_instance
 
        return render('/switch_to_list.html')
 
        if request.is_xhr:
 
            return render('/switch_to_list.html')
 
        else:
 
            return HTTPBadRequest()
rhodecode/templates/base/base.html
Show inline comments
 
@@ -149,60 +149,6 @@
 
                            <a href="#">${_('loading...')}</a>
 
                        </li>
 
					</ul>
 
					<script type="text/javascript">
 
					   YUE.on('repo_switcher','mouseover',function(){
 
						      function qfilter(){
 
						         var S = YAHOO.util.Selector;
 
						         
 
						         var q_filter = YUD.get('q_filter_rs');
 
						         var F = YAHOO.namespace('q_filter_rs'); 
 
						         
 
						         YUE.on(q_filter,'click',function(){
 
						            q_filter.value = '';
 
						         });
 
						    
 
						         F.filterTimeout = null;
 
						         
 
						         F.updateFilter  = function() { 
 
						            // Reset timeout 
 
						            F.filterTimeout = null;
 
						            
 
						            var obsolete = [];
 
						            var nodes = S.query('ul#repo_switcher_list li a.repo_name');
 
						            var req = YUD.get('q_filter_rs').value;
 
						            for (n in nodes){
 
						                YUD.setStyle(nodes[n].parentNode,'display','')
 
						            }
 
						            if (req){
 
						                for (n in nodes){
 
						                    if (nodes[n].innerHTML.toLowerCase().indexOf(req) == -1) {
 
						                        obsolete.push(nodes[n]); 
 
						                    }
 
						                }
 
						                if(obsolete){
 
						                    for (n in obsolete){
 
						                        YUD.setStyle(obsolete[n].parentNode,'display','none');
 
						                    }
 
						                }
 
						            }
 
						         }
 
						         
 
						         YUE.on(q_filter,'keyup',function(e){
 
						             clearTimeout(F.filterTimeout); 
 
						             F.filterTimeout = setTimeout(F.updateFilter,600); 
 
						         });
 
						}
 
						   var loaded = YUD.hasClass('repo_switcher','loaded');
 
						   if(!loaded){
 
							   YUD.addClass('repo_switcher','loaded');
 
							   ypjax("${h.url('repo_switcher')}",'repo_switcher_list',
 
								   function(o){qfilter();},
 
								   function(o){YUD.removeClass('repo_switcher','loaded');}
 
								   ,null);
 
						   }
 
						   return false;
 
					   });
 
					</script>	
 
				</li>
 
				
 
	            <li ${is_current('summary')}>
 
@@ -231,38 +177,15 @@
 
                </li>   	
 
                
 
                <li ${is_current('switch_to')}>
 
                   <a title="${_('Switch to')}" href="#">
 
                   <a id="branch_tag_switcher" title="${_('Switch to')}" href="#">
 
                   <span class="icon">
 
                       <img src="${h.url('/images/icons/arrow_switch.png')}" alt="${_('Switch to')}" />
 
                   </span>
 
                   <span>${_('Switch to')}</span>                 
 
                   </a>    
 
                    <ul>
 
                        <li>
 
                            ${h.link_to('%s (%s)' % (_('branches'),len(c.rhodecode_repo.branches.values()),),h.url('branches_home',repo_name=c.repo_name),class_='branches childs')}
 
                            <ul>
 
                            %if c.rhodecode_repo.branches.values():
 
						        %for cnt,branch in enumerate(c.rhodecode_repo.branches.items()):
 
						            <li>${h.link_to('%s - %s' % (branch[0],h.short_id(branch[1])),h.url('files_home',repo_name=c.repo_name,revision=branch[1]))}</li>
 
						        %endfor
 
						    %else:
 
						    	<li>${h.link_to(_('There are no branches yet'),'#')}</li>
 
						    %endif
 
                            </ul>                        
 
                        </li>
 
                        <li>
 
                            ${h.link_to('%s (%s)' % (_('tags'),len(c.rhodecode_repo.tags.values()),),h.url('tags_home',repo_name=c.repo_name),class_='tags childs')}
 
                            <ul>
 
                            %if c.rhodecode_repo.tags.values():
 
                                %for cnt,tag in enumerate(c.rhodecode_repo.tags.items()):
 
                                 <li>${h.link_to('%s - %s' % (tag[0],h.short_id(tag[1])),h.url('files_home',repo_name=c.repo_name,revision=tag[1]))}</li>
 
                                %endfor
 
                            %else:
 
                            	<li>${h.link_to(_('There are no tags yet'),'#')}</li>
 
                            %endif
 
                            </ul>                        
 
                        </li>                        
 
                    </ul>
 
                    <ul id="switch_to_list" class="switch_to">
 
                        <li><a href="#">${_('loading...')}</a></li>
 
                    </ul>                     
 
                </li>
 
                <li ${is_current('files')}>
 
                   <a title="${_('Files')}" href="${h.url('files_home',repo_name=c.repo_name)}">
 
@@ -329,8 +252,73 @@
 
                    <span class="short">${c.repository_forks}</span>
 
                    </a>
 
                </li>                
 
                
 
	        </ul>
 
            <script type="text/javascript">
 
               YUE.on('repo_switcher','mouseover',function(){
 
                      function qfilter(){
 
                         var S = YAHOO.util.Selector;
 
                         
 
                         var q_filter = YUD.get('q_filter_rs');
 
                         var F = YAHOO.namespace('q_filter_rs'); 
 
                         
 
                         YUE.on(q_filter,'click',function(){
 
                            q_filter.value = '';
 
                         });
 
                    
 
                         F.filterTimeout = null;
 
                         
 
                         F.updateFilter  = function() { 
 
                            // Reset timeout 
 
                            F.filterTimeout = null;
 
                            
 
                            var obsolete = [];
 
                            var nodes = S.query('ul#repo_switcher_list li a.repo_name');
 
                            var req = YUD.get('q_filter_rs').value.toLowerCase();
 
                            for (n in nodes){
 
                                YUD.setStyle(nodes[n].parentNode,'display','')
 
                            }
 
                            if (req){
 
                                for (n in nodes){
 
                                    if (nodes[n].innerHTML.toLowerCase().indexOf(req) == -1) {
 
                                        obsolete.push(nodes[n]); 
 
                                    }
 
                                }
 
                                if(obsolete){
 
                                    for (n in obsolete){
 
                                        YUD.setStyle(obsolete[n].parentNode,'display','none');
 
                                    }
 
                                }
 
                            }
 
                         }
 
                         
 
                         YUE.on(q_filter,'keyup',function(e){
 
                             clearTimeout(F.filterTimeout); 
 
                             F.filterTimeout = setTimeout(F.updateFilter,600); 
 
                         });
 
                }
 
                   var loaded = YUD.hasClass('repo_switcher','loaded');
 
                   if(!loaded){
 
                       YUD.addClass('repo_switcher','loaded');
 
                       ypjax("${h.url('repo_switcher')}",'repo_switcher_list',
 
                           function(o){qfilter();},
 
                           function(o){YUD.removeClass('repo_switcher','loaded');}
 
                           ,null);
 
                   }
 
                   return false;
 
               });
 

	
 
            YUE.on('branch_tag_switcher','mouseover',function(){
 
               var loaded = YUD.hasClass('branch_tag_switcher','loaded');
 
               if(!loaded){
 
                   YUD.addClass('branch_tag_switcher','loaded');
 
                   ypjax("${h.url('branch_tag_switcher',repo_name=c.repo_name)}",'switch_to_list',
 
                       function(o){},
 
                       function(o){YUD.removeClass('branch_tag_switcher','loaded');}
 
                       ,null);
 
               }
 
               return false;
 
            });
 
            </script>             
 
		%else:
 
		    ##ROOT MENU
 
            <ul id="quick">
 
@@ -373,5 +361,5 @@
 
                </li>
 
				%endif
 
			</ul>
 
		%endif    
 
		%endif
 
</%def>
rhodecode/templates/switch_to_list.html
Show inline comments
 
new file 100644
 
## -*- coding: utf-8 -*-                        
 
<li>
 
    ${h.link_to('%s (%s)' % (_('branches'),len(c.rhodecode_repo.branches.values()),),h.url('branches_home',repo_name=c.repo_name),class_='branches childs')}
 
    <ul>
 
    %if c.rhodecode_repo.branches.values():
 
        %for cnt,branch in enumerate(c.rhodecode_repo.branches.items()):
 
            <li>${h.link_to('%s - %s' % (branch[0],h.short_id(branch[1])),h.url('files_home',repo_name=c.repo_name,revision=branch[1]))}</li>
 
        %endfor
 
    %else:
 
        <li>${h.link_to(_('There are no branches yet'),'#')}</li>
 
    %endif
 
    </ul>                        
 
</li>
 
<li>
 
    ${h.link_to('%s (%s)' % (_('tags'),len(c.rhodecode_repo.tags.values()),),h.url('tags_home',repo_name=c.repo_name),class_='tags childs')}
 
    <ul>
 
    %if c.rhodecode_repo.tags.values():
 
        %for cnt,tag in enumerate(c.rhodecode_repo.tags.items()):
 
         <li>${h.link_to('%s - %s' % (tag[0],h.short_id(tag[1])),h.url('files_home',repo_name=c.repo_name,revision=tag[1]))}</li>
 
        %endfor
 
    %else:
 
        <li>${h.link_to(_('There are no tags yet'),'#')}</li>
 
    %endif
 
    </ul>                        
 
</li>  
 
\ No newline at end of file
0 comments (0 inline, 0 general)