There is a lot of duplicated logic between the two; and we can rewrite just the data access bits and share the logic between the two.
(work initially started at D3194 a few months ago, but I rewrote it as a bunch of smaller diffs, attached to this task)