Skip to content

perf(translation): E-04 E-06 share in-flight translations and translate each caption once - #61

Closed
navidshad wants to merge 1 commit into
devfrom
analytics-fixes/E-04-E-06-translation-dedupe
Closed

navidshad wants to merge 1 commit into
devfrom
analytics-fixes/E-04-E-06-translation-dedupe

Conversation

@navidshad

Copy link
Copy Markdown
Collaborator

What

  • E-04 — share translations already in flight. TranslateService keeps a map of requests on their way, by cache key. If the same call comes in before the first one answers, it waits for that request and gets the same answer. Only one network call goes out. The entry is removed when the request settles. A failure reaches every waiting caller and is never cached.
  • E-06 — translate each caption once. New helper src/subtitle/helpers/caption-translation-gate.ts, used by web_netflix/components/Subtitle.vue and _support-template/components/Subtitle.vue. With "translate whole caption" on:
    • It waits about 150 ms for the caption to settle.
    • It skips the request when the joined caption equals the one already translated on screen (for example, a caption that blinks off and back on).
    • A new caption clears the old translation at once, so the old text is not shown under the new caption while it settles.
    • A failed caption can be sent again.
    • Turning the option on still translates at once (no wait).

Why

The cache was filled only after the answer came back, so two calls for the same text at the same time both went out. The caption watcher sent a request on every caption change, sometimes more than once for one caption. Work list: subturtle-doc docs/tech/analytics-fixes-implementation.md (rows E-04, E-06).

How tested

  • New unit tests: in-flight cases in tests/translate.service.test.ts (one request for two calls, detailed too, different keys not shared, failure reaches both callers and is not kept) and tests/caption-translation-gate.test.ts (settle delay, skip same caption, A → B → A, send now, retry after failure, cancel).
  • yarn typecheck: clean.
  • yarn test: 41 files, 369 tests pass.
  • yarn build: OK.
  • The repo has no lint script.
  • Not checked on real Netflix (the caption path cannot run in our test setup; see CLAUDE.md "Still manual").

Dependencies

🤖 Generated with Claude Code

…te each caption once

- E-04: TranslateService keeps a map of requests in flight by cache key.
  An identical call made before the first one answers waits for it and
  gets the same answer, so only one request goes out. The entry is removed
  when the request settles; a failure reaches every waiting caller and is
  never cached.
- E-06: new src/subtitle/helpers/caption-translation-gate.ts. With
  "translate whole caption" on, the Netflix and support-template caption
  components wait about 150 ms for the caption to settle, then send it
  only when the joined text differs from the caption already translated
  on screen. A failed caption can be sent again. Turning the option on
  still translates at once.
- Tests: in-flight cases in tests/translate.service.test.ts, new
  tests/caption-translation-gate.test.ts.

Work list: subturtle-doc docs/tech/analytics-fixes-implementation.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@navidshad

Copy link
Copy Markdown
Collaborator Author

Replaced by #62, which combines all extension rows (E-01 to E-06) into one PR.

@navidshad navidshad closed this Oct 16, 2026
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