Mercurial > kallithea
changeset 1608:0069657aaf42 beta
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
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 29 Oct 2011 00:57:09 +0200 |
parents | e886f91fcb71 |
children | aaabec656ceb |
files | rhodecode/config/routing.py rhodecode/controllers/home.py rhodecode/templates/base/base.html rhodecode/templates/switch_to_list.html |
diffstat | 4 files changed, 107 insertions(+), 83 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/config/routing.py Fri Oct 28 02:40:22 2011 +0200 +++ b/rhodecode/config/routing.py Sat Oct 29 00:57:09 2011 +0200 @@ -62,6 +62,8 @@ 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)
--- a/rhodecode/controllers/home.py Fri Oct 28 02:40:22 2011 +0200 +++ b/rhodecode/controllers/home.py Sat Oct 29 00:57:09 2011 +0200 @@ -58,3 +58,12 @@ 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()
--- a/rhodecode/templates/base/base.html Fri Oct 28 02:40:22 2011 +0200 +++ b/rhodecode/templates/base/base.html Sat Oct 29 00:57:09 2011 +0200 @@ -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>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rhodecode/templates/switch_to_list.html Sat Oct 29 00:57:09 2011 +0200 @@ -0,0 +1,25 @@ +## -*- 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