Skip to content

Remove duplicated code around waiting for shared work - #5463

Merged
marcelveldt merged 1 commit into
devfrom
dedupe-join-task
Aug 7, 2026
Merged

Remove duplicated code around waiting for shared work#5463
marcelveldt merged 1 commit into
devfrom
dedupe-join-task

Conversation

@marcelveldt

Copy link
Copy Markdown
Member

What does this implement/fix?

PR #5453 added a join_task() helper for waiting on work that is shared between callers. Seven older call sites still had their own copy of exactly the same code, each with the same five-line explanation attached, so the codebase had two ways of doing one thing.

These now all use the helper. No behaviour change — the helper does exactly what the inlined code did, and the existing tests pass untouched.

  • Converted the remaining hand-rolled waits in helpers/util.py, helpers/colors.py, helpers/images.py and models/recommendation_payload.py to join_task()
  • Dropped the duplicated explanation comments (that reasoning now lives in the helper itself), keeping the one site-specific note

Types of changes

  • Bugfix (non-breaking change which fixes an issue) — bugfix
  • New feature (non-breaking change which adds functionality) — new-feature
  • Enhancement to an existing feature — enhancement
  • New music/player/metadata/plugin provider — new-provider
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — breaking-change
  • Refactor (no behaviour change) — refactor
  • Documentation only — documentation
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Checklist

  • The code change is tested and works locally.
  • pre-commit run --all-files passes.
  • pytest passes, and tests have been added/updated under tests/ where applicable.
  • For changes to shared models, the companion PR in music-assistant/models is linked.
  • For changes affecting the UI, the companion PR in music-assistant/frontend is linked.
  • I have read and complied with the project's AI Policy for any AI-assisted contributions.
  • I have raised a PR against the documentation repository targeting the main or beta branch as appropriate.

Copilot AI lite review requested due to automatic review settings August 7, 2026 17:39
@codspeed-hq

codspeed-hq Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 11 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing dedupe-join-task (98b9e58) with dev (ca99807)2

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on dev (b6b5e93) during the generation of this report, so ca99807 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes duplicated “shared work waiting” logic by switching remaining call sites to the existing join_task() helper, consolidating the cancellation-safe waiting behavior in one place without changing runtime behavior.

Changes:

  • Replaced several instances of await asyncio.wait((task,)); task.result() with return await join_task(task).
  • Removed duplicated explanatory comments at call sites, keeping only context-specific notes where needed.
  • Added join_task imports in modules that previously used the inline pattern.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
music_assistant/models/recommendation_payload.py Uses join_task() for shared payload fetch/refresh tasks, preserving non-cancelling waiter behavior while reducing duplicated code/comments.
music_assistant/helpers/util.py Updates remaining internal single-flight wait sites to use join_task() (including guard_single_request), centralizing the cancellation-safe wait behavior.
music_assistant/helpers/images.py Switches shared image fetch and thumbnail generation waits to join_task() and imports it.
music_assistant/helpers/colors.py Switches shared palette extraction wait to join_task() and imports it.

@marcelveldt
marcelveldt marked this pull request as ready for review August 7, 2026 19:25
Copilot AI review requested due to automatic review settings August 7, 2026 19:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 7, 2026 20:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@marcelveldt
marcelveldt merged commit ef606b8 into dev Aug 7, 2026
18 checks passed
@marcelveldt
marcelveldt deleted the dedupe-join-task branch August 7, 2026 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants