diff options
author | Dan McGee <dan@archlinux.org> | 2010-10-26 14:04:54 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2010-10-26 14:43:47 -0500 |
commit | 1a8114c00f22252b6e2b0c4a741f0bea1de5dd1d (patch) | |
tree | ad19c256329ac89e18518a9576770ec119a249af /media/archweb.js | |
parent | 576118c45ca4605eaf874fba3d95969c08a7c7d4 (diff) |
Make package differences JS a bit more efficient
Use an id-based selector so we can get the necessary table rows to filter a
lot more quickly than a lengthy CSS selector. Also use traversal rather than
selectors when grabbing the package versions. This looked like a 3x-4x
increase in speed while testing locally.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'media/archweb.js')
-rw-r--r-- | media/archweb.js | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/media/archweb.js b/media/archweb.js index 5e315f35..c5025ded 100644 --- a/media/archweb.js +++ b/media/archweb.js @@ -57,9 +57,10 @@ function enablePreview() { $.post('/news/preview/', { data: $('#id_content').val() }, function(data) { - $('#previewdata').html(data); - $('.news-article').show(); - }); + $('#previewdata').html(data); + $('.news-article').show(); + } + ); $('#previewtitle').html($('#id_title').val()); }); } @@ -77,7 +78,8 @@ function ajaxifyFiles() { /* packages/differences.html */ filter_packages = function() { // start with all rows, and then remove ones we shouldn't show - var rows = $(".results tbody tr"); + var rows = $("#tbody_differences").children(); + var all_rows = rows; if(!$('#id_multilib').is(':checked')) { rows = rows.not(".multilib").not(".multilib-testing"); } @@ -87,32 +89,36 @@ filter_packages = function() { } if(!$('#id_minor').is(':checked')) { // this check is done last because it is the most expensive + var pat = /(.*)-(.+)/; rows = rows.filter(function(index) { + var cells = $(this).children('td'); + // all this just to get the split version out of the table cell - var pat = /(.*)-(.+)/; - var ver_a = $('td:eq(2) span', this).text().match(pat); - var ver_b = $('td:eq(3) span', this).text().match(pat); - // did we match at all? - if(!ver_a || !ver_b) return true; + var ver_a = cells.eq(2).find('span').text().match(pat); + if(!ver_a) return true; + + var ver_b = cells.eq(3).find('span').text().match(pat); + if(!ver_b) return true; + // first check pkgver if(ver_a[1] !== ver_b[1]) return true; // pkgver matched, so see if rounded pkgrel matches - if(Math.floor(parseFloat(ver_a[2])) == - Math.floor(parseFloat(ver_b[2]))) return false; + if(Math.floor(parseFloat(ver_a[2])) == + Math.floor(parseFloat(ver_b[2]))) return false; // pkgrel didn't match, so keep the row return true; }); } // hide all rows, then show the set we care about - $('.results tbody tr').hide(); + all_rows.hide(); rows.show(); // make sure we update the odd/even styling from sorting $('.results').trigger("applyWidgets"); }; filter_reset = function() { - $('#id_archonly').val("all"); + $('#id_archonly').val("both"); $('#id_multilib').removeAttr("checked"); - $('#id_minor').attr("checked", "checked"); + $('#id_minor').removeAttr("checked"); filter_packages(); }; |