@@ -242,6 +242,23 @@ def search_base_query(
242242 ordering : str ,
243243 cursor : CursorValue | None ,
244244) -> list [TestResultsRow ]:
245+ """
246+ The reason we have to do this filtering in the application logic is because we need to get the total count of rows that
247+ match from the base query, but we only want to return the rows from after the cursor, so to avoid doing multiple SQL queries
248+ to get the total count of rows that match and then filtering in the database we do the filtering here.
249+
250+ This is a binary search to find the cursor based on the ordering field.
251+
252+ The base query we get back is not filtered, we need to filter the rows in the application logic here
253+ so we decode the cursor, which is a value for the ordering field (based on the OrderingParameter) and
254+ a value for the name field.
255+
256+ The list of rows we get back from the base query is ordered by the ordering field, then by name, so we
257+ can do a binary search to find the value corresponding to the cursor.
258+
259+ When we find the value corresponding to the cursor we return the rows starting from there, and then we filter
260+ by the page size after we call this function.
261+ """
245262 if not cursor :
246263 return rows
247264
@@ -256,7 +273,6 @@ def compare(row: TestResultsRow) -> int:
256273
257274 left , right = 0 , len (rows ) - 1
258275 while left <= right :
259- print (left , right )
260276 mid = (left + right ) // 2
261277 comparison = compare (rows [mid ])
262278
@@ -298,9 +314,9 @@ def generate_test_results(
298314 :param branch: optional name of the branch we want to filter on, if this is provided the aggregates calculated will only take into account
299315 test instances generated on that branch. By default branches will not be filtered and test instances on all branches wil be taken into
300316 account.
301- :param interval: timedelta for filtering test instances used to calculated the aggregates by time, the test instances used will be
317+ :param interval: timedelta for filtering test instances used to calculate the aggregates by time, the test instances used will be
302318 those with a created at larger than now - interval.
303- :param testsuites: optional list of testsuite names to filter by
319+ :param testsuites: optional list of testsuite names to filter by, this is done via a union
304320 :param flags: optional list of flag names to filter by, this is done via a union so if a user specifies multiple flags, we get all tests with any
305321 of the flags, not tests that have all of the flags
306322 :returns: queryset object containing list of dictionaries of results
0 commit comments