Skip to content

Commit

Permalink
Speed-up TestCase filtering on the TestPlan view page
Browse files Browse the repository at this point in the history
by collecting a list of DOM selectors to be queried/shown via jQuery
multiple-selector at the same time instead of calling .show() for each
one of them.

For 1-2 rows this is on-par with the previous implementation, however it is
around 2x faster when the result set contains many rows (say 100 or
1000).

WARNING: when a result set contains hundreds of rows there is still a
noticeable lag on the page. For example if filtering 1000 rows for
is_automated=false, where only 10 rows have the value of True and the
rest 990 have the value of False!

See https://api.jquery.com/multiple-selector/
  • Loading branch information
atodorov committed Nov 19, 2024
1 parent 028d62a commit 54833e5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tcms/testplans/static/testplans/js/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,18 +696,25 @@ function filterTestCasesByProperty (planId, testCases, filterBy, filterValue) {
}

$('.js-testcase-row').hide()

// see https://api.jquery.com/multiple-selector/
const showOnly = []
if (filterBy === 'component' || filterBy === 'tag') {
const query = { plan: planId }
query[`${filterBy}__name__icontains`] = filterValue

jsonRPC('TestCase.filter', query, function (filtered) {
// hide again if a previous async request showed something else
$('.js-testcase-row').hide()
filtered.forEach(tc => $(`[data-testcase-pk=${tc.id}]`).show())
filtered.forEach(tc => showOnly.push(`[data-testcase-pk=${tc.id}]`))

$(showOnly.join(',')).show()
})
} else {
testCases.filter(function (tc) {
return (tc[filterBy] !== undefined && tc[filterBy].toString().toLowerCase().indexOf(filterValue) > -1)
}).forEach(tc => $(`[data-testcase-pk=${tc.id}]`).show())
}).forEach(tc => showOnly.push(`[data-testcase-pk=${tc.id}]`))

$(showOnly.join(',')).show()
}
}

0 comments on commit 54833e5

Please sign in to comment.