-
Alfredo Di Napoli authored
The refactored DB API now has a separate building block to create an Opaleye query that counts the number of returned results; we do that via `countRows`, exactly like the previous version. However, I have discovered a small footgun in the Opaleye API -- if you have two `Select` statements both calling countRows in a chain, that will always yield a value of 1, because the inner `countRows` will give you the actual number of results by returning a single row with an integer inside (i.e. the count). However, the subsequent (outer) call to `countRows` will return the number of rows of the previous step .. which is always going to be one! The bug was that I had left somewhere the spurious `countRows` in the query which would return the number of documents needed for the TFICF field, triggering the bug (because then we had `it` ALWAYS equal to 1.0). In the new API, while we cannot prevent the bug at the type level we can easily do an audit by grepping for `countRows`, making sure we have exactly one instance, i.e. inside `mkOpaCountQuery`.