Skip to content

πŸ› fix: bypass DAO cache in isSegmentDisabled to prevent stale disabled …#4552

Open
mauretto78 wants to merge 1 commit intodevelopfrom
fix-segment-analysis
Open

πŸ› fix: bypass DAO cache in isSegmentDisabled to prevent stale disabled …#4552
mauretto78 wants to merge 1 commit intodevelopfrom
fix-segment-analysis

Conversation

@mauretto78
Copy link
Copy Markdown
Contributor

Summary

Fix isSegmentDisabled returning stale false values due to DAO-level cache (1-week TTL) not being invalidated when a segment is disabled.

Type

  • fix β€” bug fix

Changes

File Change
lib/Controller/Traits/SegmentDisabledTrait.php Pass ttl: 0 to SegmentMetadataDao::get() to bypass the DAO cache, which was serving stale results for up to 1 week

Testing

  • vendor/bin/phpunit --exclude-group=ExternalServices --no-coverage passes
  • ./vendor/bin/phpstan passes (0 errors, with baseline)
  • Manual testing performed (describe below)
  • New tests added for changed behavior
  • Regression tests added for bug fixes

Verified that after disabling a segment via setTranslationDisabled, the segment-analysis API correctly returns disabled: true without waiting for cache expiry.

AI Disclosure

  • No AI tools were used in this PR
  • AI tools were used β€” details below

GitHub Copilot

Notes

Root cause: SegmentMetadataDao::get() defaults to a 604800s (1 week) TTL. When isSegmentDisabled queried a segment before it was disabled, the DAO cache stored an empty result for 1 week. Subsequent calls to setTranslationDisabled wrote the DB row but never invalidated this specific DAO cache entry, so isSegmentDisabled kept returning false.

Fix: Since isSegmentDisabled already manages its own Redis cache layer (1-hour TTL) with proper invalidation via destroySegmentDisabledCache and saveSegmentDisabledInCache, the DAO-level cache is redundant. Setting ttl: 0 bypasses it.

Copilot AI review requested due to automatic review settings April 30, 2026 15:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes isSegmentDisabled returning stale false values by bypassing the DAO-level Redis query cache (default 1-week TTL) when checking translation_disabled, relying instead on the trait’s own cache layer/invalidation.

Changes:

  • Bypass SegmentMetadataDao::get() caching in isSegmentDisabled() by passing ttl = 0.
  • Ensure disabled state is determined from fresh DB reads on cache miss, then stored in the trait cache.

Comment on lines 52 to 55
if (empty($cachedValue)) {
$metadataList = SegmentMetadataDao::get($id_segment, 'translation_disabled');
$metadataList = SegmentMetadataDao::get($id_segment, 'translation_disabled', 0);
$metadata = $metadataList[0] ?? null;
$isDisabled = (($metadata->meta_value ?? '0') === '1');
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

isSegmentDisabled()'s cache-miss path behavior changed (DAO cache bypass via ttl=0), but the existing unit tests for this trait only cover the Redis-hit path and skip DB/DAO interactions. Please add coverage for the cache-miss branch (e.g., by extracting the SegmentMetadataDao::get(...) call into an overridable method or injecting a DAO so the test can assert the ttl=0 behavior without a real DB).

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown

πŸ§ͺ Test-Guard Report

❌ FAIL β€” Some changed source files lack adequate test coverage.

Coverage Analysis: ❌ FAIL

No changed source files found in coverage report (threshold: 80%)

File Verdict Reason
lib/Controller/Traits/SegmentDisabledTrait.php ❌ fail not in coverage report

Test File Matching: ⚠️ WARNING

File matching: 1 warning

File Verdict Reason
lib/Controller/Traits/SegmentDisabledTrait.php ⚠️ warning Test file exists (tests/unit/Traits/SegmentDisabledTraitTest.php) but was not modified in this PR

Per-File Evaluation: ❌ FAIL

All files resolved by deterministic shortcuts.

File Verdict Reason
lib/Controller/Traits/SegmentDisabledTrait.php ❌ fail shortcut β†’ no relevant tests in PR and no/low coverage

Result: ❌ FAIL


Why this FAIL?

  • Coverage Analysis: lib/Controller/Traits/SegmentDisabledTrait.php is missing from the coverage report, indicating a coverage configuration issue β†’ update coverage instrumentation or filters to include this file.
  • Test File Matching: The existing test file tests/unit/Traits/SegmentDisabledTraitTest.php was not modified in this PR β†’ no action needed; tests exist but were not changed.
  • Per-File Evaluation: No relevant tests were added or modified in this PR for lib/Controller/Traits/SegmentDisabledTrait.php, and coverage is missing β†’ add or modify tests to cover changes or fix coverage config.

To resolve: update coverage configuration to include lib/Controller/Traits/SegmentDisabledTrait.php and add or modify tests to cover the changes.

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.

2 participants