# HG changeset patch # User Mads Kiilerich # Date 1473115878 -7200 # Node ID d9757113c013b789efc323a76e8430c56ce543b9 # Parent 9b80c2a647815bbec289b0b932e9f1a375f100c8 files: improve select2 performance with many branches Do to this select2 what was done to compare_diff and others in cc18e56220a2 and elsewhere. diff -r 9b80c2a64781 -r d9757113c013 kallithea/templates/files/files.html --- a/kallithea/templates/files/files.html Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/templates/files/files.html Tue Sep 06 00:51:18 2016 +0200 @@ -149,22 +149,30 @@ $("#diff1").select2({ placeholder: _TM['Select changeset'], dropdownAutoWidth: true, + maxResults: 50, query: function(query){ var key = 'cache'; var cached = cache[key] ; if(cached) { var data = {results: []}; + var queryLower = query.term.toLowerCase(); //filter results $.each(cached.results, function(){ var section = this.text; var children = []; $.each(this.children, function(){ - if(query.term.length == 0 || this.text.toUpperCase().indexOf(query.term.toUpperCase()) >= 0 ){ - children.push({'id': this.id, 'text': this.text}); + if(children.length < 50 ? + ((queryLower.length == 0) || (this.text.toLowerCase().indexOf(queryLower) >= 0)) : + ((queryLower.length != 0) && (this.text.toLowerCase().indexOf(queryLower) == 0))) { + children.push(this); } }); + children = branchSort(children, undefined, query) data.results.push({'text': section, 'children': children}); }); + //push the typed in changeset + data.results.push({'text':_TM['Specify changeset'], + 'children': [{'id': query.term, 'text': query.term, 'type': 'rev'}]}); query.callback(data); }else{ $.ajax({ @@ -174,7 +182,7 @@ type: 'GET', success: function(data) { cache[key] = data; - query.callback({results: data.results}); + query.callback(data); } }); }