Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review the Javascript about the evidence table for performance and code quality. #726

Closed
marco-brandizi opened this issue Mar 10, 2023 · 2 comments
Labels
code quality project:client Related to the client/front-end war.

Comments

@marco-brandizi
Copy link
Member

marco-brandizi commented Mar 10, 2023

The function createEvidenceTable() in evidence-table.js has poor code that performs badly.

  • values is a bad name, it actually means row or rowValues

  • values[0], values[1], values[] everywhere is kindergarten programming, which makes the code unreadable and error-prone. At the top of the row-rendering iteration, it should have something like:

var [ conceptType, conceptLabel, pvalue, ... ] = values // or, as said, 'row'

And then the semantically-meaningful names should be used, not the damn indices, even Assembler programmers use symbolic constants to index memory!

  • userGenes is turned into an array (via String.split()) for the sole purpose of counting how many genes there are in the string. This is likely to be the performance bottleneck we're currently experiencing.

The count should be based on the no. of ',' (in a non-empty string) + 1. Write a support function (or use some existing lib) to count the occurrences of a substring in another via indexOf(), as shown here.

==> this is a temporary quick fix, the alternative is to take more time to change the API and make it return the count.

  • This is redundant ugly code:
table += '<option value="1000"' + (rows == 1000 ? 'selected' : '') + '>1000 </option>';
table += '<option value="500"' + (rows == 500 ? 'selected' : '') + '>500</option>';
table += '<option value="200"' + (rows == 200 ? 'selected' : '') + '>200</option>';
table += '<option value="100"' + (rows == 100 ? 'selected' : '') + '>100</option>';
table += '<option value="50"' + (rows == 50 ? 'selected' : '') + '>50</option>';

Write a support function (even an anonymous in-line function is better than the current copy-paste mess) which loops over rowsLimit = range of 50, 100, 200, 500, 1000 and writes the <option> row only once.

Generally speaking, in future we should review these mixes of HTML and javascript, see #725

  • Various other improvements (can be done later) added as TODO comments in the code.
@marco-brandizi
Copy link
Member Author

When cutting the initial list to the top 100, such list needs to be sorted. See #727 regarding getting this from the API. This is still on a branch and needs unit tests + UI tests.

@marco-brandizi
Copy link
Member Author

marco-brandizi commented Mar 16, 2023

@lawal-olaotan the initial table sorting is still wrong, see last comments. The other TODOs are not urgent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality project:client Related to the client/front-end war.
Projects
None yet
Development

No branches or pull requests

1 participant