dbworker: allow `Scan` functions to return multiple records
Created by: LawnGnome
There's a disconnect in the Scan
callback for dbworker stores right now — they are given a Rows
object that represents a full resultset that can contain more than one row, but the return value only ever returns the first row.
Practically, this isn't a problem at present because the only use of Scan
is in Dequeue
, which is limited to only returning zero or one records due to the LIMIT 1
in the candidate
CTE. However, I intend to add another method to the Store
interface to allow accessing jobs that are currently processing as part of #27546, and that will need to be able to scan multiple rows in a resultset.
Also, I just think this is a less leaky abstraction.
The actual change here is pretty minimal, and most (if not all) users of dbworker stores actually end up with simpler code, since this allows us to more easily reuse existing scan functions that are used by more general database methods (usually Get
and List
methods) with only a simple generic shim to create the callback. Batch Changes stores require an additional shim due to historic differences in how scan functions are structured in that part of the codebase, but I still think it's considerably simpler than what was there before.
Test plan
I've tested this both by pushing jobs through dbworkers and executors in a Batch Changes context, and through unit test coverage.