refactor: dedupe service/collector helper twins (#1135)#1285
Open
axisrow wants to merge 1 commit into
Open
Conversation
Five genuine (non-parity) clones across services/ and telegram/: * channel_analytics_service._calc_err / _calc_err24 duplicated the engagement-rate formula (sum / rows*subs * 100); extracted _engagement_rate(rows) — each caller keeps its own data fetch. * pipeline_nodes/handlers duplicated the context_messages -> source block in LlmGenerateHandler and AgentLoopHandler; extracted module-level _build_source_messages(messages). Behaviour identical: blank texts dropped, same [header] text (id:.. date:..) format, blank-joined; the truthiness guard on the agent-loop user_message is preserved (the joined string is empty iff the parts list was empty). * telegram_actions.download_media / download_media_sized duplicated the resolve-entity + iter_messages(ids=) lookup + MessageNotFoundError raise; extracted _fetch_message_with_flood_wait(client, phone, entity, id). * photo_task_service.send_now / schedule_send duplicated the PhotoBatch + PhotoBatchItem construction (parameterized by status + started_at vs schedule_at); extracted _create_send_batch_item returning (batch_id, item_id). * collector_mixins/stats stats_*worker_count and available_stats_*_worker_count were two pairs of twins differing only by config attr / default / log label; extracted _configured_worker_count and _available_worker_count. 1359 targeted tests pass. jscpd total holds at 0.67% (clones from these files removed; remaining clones are parity/declarative — see PR #1135 notes). Part of #1135 (axis 5 of #1130). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #1135 (axis 5 of #1130). Five genuine (non-parity) clones across
services/andtelegram/.Clones & extraction
channel_analytics_service._calc_err↔_calc_err24_engagement_rate(channel_id, rows)sum / (rows*subs) * 100. Each caller keeps its own data fetch (get_err_datavsget_err24_data).pipeline_nodes/handlerssource block (LlmGenerate + AgentLoop)_build_source_messages(messages)[header] text (id:.. date:..)rendering, blank-joined; blank texts dropped. The AgentLoopuser_messagetruthiness guard is preserved (joined string empty ⟺ parts list empty).telegram_actions.download_media↔download_media_sizedlookup_fetch_message_with_flood_wait(...)iter_messages(ids=)under flood-wait +MessageNotFoundErrorraise.photo_task_service.send_now↔schedule_sendbatch+item ctor_create_send_batch_item(..., status, schedule_at)→(batch_id, item_id)started_atvsschedule_at.collector_mixins/statsstats_*worker_count+available_stats_*worker_count(2 pairs)_configured_worker_count,_available_worker_countVerification
analytics/err/pipeline_node/telegram_action/download_media/photo_task/collector_stats/worker_count/source_messages).jscpd
Total: 0.67%(49 clones) — flat vs. the PR-2 state. The remainingservices/telegram_actions.py:575↔594andcollector_mixins/cancellation↔statshits are parity-style Telegram-error-handling blocks and the shared TYPE_CHECKINGCollectorProtocol (see tech-debt: дедуп кода (jscpd 0.56%, не-parity клоны) #1135 parity notes), intentionally untouched.Part of #1135 / #1130. Not for merge — review requested.
🤖 Generated with Claude Code