tidy(versioning): extract shared helpers between list_versions and get_version
After the SRP split (8c9cf36) put both functions in the same module
~150 lines apart, their overlap became visible: same JOIN of
version_table → version_transaction → ab_user, same baseline-first
ordering, same user-row → ``changed_by`` projection, same lookup
``_ENTITY_KIND_BY_CLASS_NAME.get(model_cls.__name__)``. About 30 lines
of duplication.
Five small helpers extracted at the module top:
- ``_resolve_version_tables(model_cls)`` returns ``(ver_tbl, tx_tbl, user_tbl)``
- ``_version_with_tx_user_join(ver_tbl, tx_tbl, user_tbl)`` builds the join
- ``_baseline_first_ordering(ver_tbl)`` returns the order-by tuple
- ``_user_select_cols(user_tbl)`` returns the user-column list with
``user_id`` as the stable label (normalises the prior asymmetry
where ``list_versions`` labelled it ``user_id`` and ``get_version``
labelled it ``_user_id`` to dodge a column-name collision — the
``user_id`` label collides with neither)
- ``_changed_by_from_row(row)`` projects user columns onto the API shape
- ``_entity_kind_for(model_cls)`` resolves the change-records taxonomy lookup
Both call sites get shorter and read what they do (build query / project
user / build row) rather than how. Behavior unchanged; no test changes.
Also two small inline tidyings while in the file:
- Replace the ternary
``changes_by_tx = list_change_records_batch(...) if entity_kind else {}``
with an explicit two-line if-statement in both functions. The ternary
buries the decision; the if-statement reads as one thought.
- Inline the one-shot ``meta_cols`` set declaration in ``get_version``
into the ``if col.name in {...}`` check that uses it three lines later.
Net: about 110 lines → about 80 lines across the two functions, plus
a small helper section at the top. M
Mike Bridge committed
77c373616e3731ca2bca87c4e9e5724356d73b70
Parent: 40653d5