Skip to content

refactor(db): dedupe cross-bundle wrappers into shared mixins (#1135)#1283

Open
axisrow wants to merge 1 commit into
mainfrom
ao/tg_content_factory_5863f66be3-63/dedup-bundles
Open

refactor(db): dedupe cross-bundle wrappers into shared mixins (#1135)#1283
axisrow wants to merge 1 commit into
mainfrom
ao/tg_content_factory_5863f66be3-63/dedup-bundles

Conversation

@axisrow

@axisrow axisrow commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Part of #1135 (axis 5 of #1130). Stays off the parity surface — only genuine within-repo duplication is touched.

What

src/database/bundles.py duplicated identical repository pass-through methods across bundles:

  • channel read/state ops — ChannelBundle + CollectionBundle
  • task create / task read — both bundles
  • get_setting/set_settingfour bundles (Collection, Notification, Search, Scheduler)
  • account reads (list_accounts, list_account_summaries) — three bundles
  • message search_messages/insert_messages_batch — Collection + Search
  • get_recent_searches — Search + Scheduler

jscpd flagged 5 clone pairs inside the file — the top cluster of #1135.

How

Each duplicated wrapper group moves into a repo-scoped plain-class mixin (_ChannelOps, _CollectionTaskCreateOps, _CollectionTaskReadOps, _SettingsOps, _NotificationQueriesOps, _MessageOps, _AccountReadOps, _SearchLogReadOps). A bundle mixes in only the groups whose repository field it already carries.

Mixins are deliberately NOT dataclasses: their attribute annotations (channels: ChannelsRepository, …) do not become dataclass fields, so every bundle's positional constructor order is unchanged.

Verification

  • Public API byte-identical — verified by an inspect.signature diff of all 10 bundle classes before/after. The only diffs are PipelineBundle.list_accounts/list_account_summaries, which gain the return-type annotations the duplicates already carried.
  • Bundle method count 138 → 111; the test_db_access_conventions ratchet baseline is lowered accordingly (it is a downward-only cap by design).
  • tests/test_bundles.py (42) + bundle consumers (scheduler, search_queries, notifier, photo_loader, pipeline_service, regression-services: 178) green.

jscpd

  • Before (this file): 5 internal clones (~80 dup lines)
  • After: 0 internal clones; the two remaining cross-file hits (bundles.py:19facade.py:18 import block; bundles.py:734photo_loader.py:456 repo pass-through) are import-boilerplate / single thin wrappers, not worth a helper.

Part of #1135 / #1130. Not for merge — review requested.

🤖 Generated with Claude Code

…1135)

bundles.py duplicated identical repository pass-through methods across
bundles (ChannelBundle/CollectionBundle channel+task ops, get_setting/
set_setting in four bundles, account reads in three, message search/batch
insert in two, scheduler task reads). jscpd flagged 5 clone pairs inside
the file — the top cluster of issue #1135.

Consolidate each duplicated wrapper group into a repo-scoped plain-class
mixin (_ChannelOps, _CollectionTaskCreateOps, _CollectionTaskReadOps,
_SettingsOps, _NotificationQueriesOps, _MessageOps, _AccountReadOps,
_SearchLogReadOps). Mixins are deliberately NOT dataclasses: their
attribute annotations do not become dataclass fields, so every bundle's
positional constructor order is unchanged.

Public API is byte-identical (verified by inspect.signature diff) except
PipelineBundle.list_accounts/list_account_summaries which gain the return
annotations the duplicates already had. Bundle method count 138 -> 111;
the test_db_access_conventions ratchet baseline is lowered accordingly.

Part of #1135 (axis 5 of #1130).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant