-
Notifications
You must be signed in to change notification settings - Fork 274
✨ feat: add segment disable/enable API for translation cancel requests #4488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
81efcdf
afc4ded
3e86ed5
bc890e9
e3e4047
606f9b0
b84ab74
00f002d
2105f92
de804bc
6c2f634
5040d59
c803e1d
d44c8e3
2dfe516
fcd77fe
789a457
4b39a72
6d8fdd7
48d9dd6
aafd8e1
7d668c1
1f26aec
b94b9b2
dfe81ba
2c1245c
8e54b2b
21f6db9
173adc0
26b9f84
e355db0
45f9314
1a7cb68
78d5ec0
d981683
45f62ef
6994a9b
a6e3077
fee5843
fec5384
4c983f0
aca6c56
8839b2e
2aa6c0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,191 @@ | ||||||||
| <?php | ||||||||
| /** | ||||||||
| * Created by PhpStorm. | ||||||||
| * User: vincenzoruffa | ||||||||
| * Date: 13/09/2018 | ||||||||
| * Time: 13:03 | ||||||||
| */ | ||||||||
|
|
||||||||
| namespace Controller\API\V3; | ||||||||
|
|
||||||||
| use Controller\Abstracts\KleinController; | ||||||||
| use Controller\API\Commons\Validators\LoginValidator; | ||||||||
| use Controller\Traits\ChunkNotFoundHandlerTrait; | ||||||||
| use Controller\Traits\RateLimiterTrait; | ||||||||
| use Controller\Traits\SegmentDisabledTrait; | ||||||||
| use Exception; | ||||||||
| use Klein\Response; | ||||||||
| use Model\DataAccess\DaoCacheTrait; | ||||||||
| use Model\Exceptions\NotFoundException; | ||||||||
| use Model\Segments\SegmentMetadataDao; | ||||||||
| use Model\Translations\SegmentTranslationDao; | ||||||||
| use Model\Translations\SegmentTranslationStruct; | ||||||||
| use Utils\Constants\TranslationStatus; | ||||||||
| use Utils\Tools\Utils; | ||||||||
|
|
||||||||
| class CancelRequestController extends KleinController | ||||||||
| { | ||||||||
| use DaoCacheTrait; | ||||||||
| use RateLimiterTrait; | ||||||||
| use SegmentDisabledTrait; | ||||||||
| use ChunkNotFoundHandlerTrait; | ||||||||
|
|
||||||||
| protected function afterConstruct(): void | ||||||||
| { | ||||||||
| $this->appendValidator(new LoginValidator($this)); | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * @throws Exception | ||||||||
| */ | ||||||||
| public function enableRequest(): void | ||||||||
| { | ||||||||
| $rawIdJob = $this->request->param('id_job'); | ||||||||
| $password = $this->request->param('password'); | ||||||||
| $rawIdSegment = $this->request->param('id_segment'); | ||||||||
| $id_job = filter_var($rawIdJob, FILTER_VALIDATE_INT); | ||||||||
| $id_segment = filter_var($rawIdSegment, FILTER_VALIDATE_INT); | ||||||||
| $route = '/api/v3/jobs/'.$id_job.'/'.$password.'/segment/enable/'.$id_segment; | ||||||||
|
|
||||||||
| $this->performChecks($id_job, $password, $id_segment, $route); | ||||||||
|
|
||||||||
| if ($this->response->code() === 429) { | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| if($this->isSegmentDisabled($id_job, $id_segment)){ | ||||||||
| $this->destroySegmentDisabledCache($id_job, $id_segment); | ||||||||
| } | ||||||||
|
|
||||||||
| $this->response->json([ | ||||||||
| 'id_segment' => $id_segment, | ||||||||
| ]); | ||||||||
| } | ||||||||
|
mauretto78 marked this conversation as resolved.
|
||||||||
|
|
||||||||
| /** | ||||||||
| * @throws Exception | ||||||||
| */ | ||||||||
| public function cancelRequest(): void | ||||||||
| { | ||||||||
| $rawIdJob = $this->request->param('id_job'); | ||||||||
| $password = $this->request->param('password'); | ||||||||
| $rawIdSegment = $this->request->param('id_segment'); | ||||||||
| $id_job = filter_var($rawIdJob, FILTER_VALIDATE_INT); | ||||||||
| $id_segment = filter_var($rawIdSegment, FILTER_VALIDATE_INT); | ||||||||
| $route = '/api/v3/jobs/'.$id_job.'/'.$password.'/segment/disable/'.$id_segment; | ||||||||
|
|
||||||||
| $this->performChecks($id_job, $password, $id_segment, $route); | ||||||||
|
|
||||||||
| if ($this->response->code() === 429) { | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| // If the cache is empty, it means that the segment is not already disabled, so we can proceed with disabling it and | ||||||||
| // setting the cache to avoid multiple disable requests for the same segment in a short time frame | ||||||||
| if (!$this->isSegmentDisabled($id_job, $id_segment)) { | ||||||||
| SegmentMetadataDao::destroyGetAllCache($id_segment); | ||||||||
|
||||||||
| SegmentMetadataDao::destroyGetAllCache($id_segment); | |
| SegmentMetadataDao::destroyGetAllCache($id_segment); | |
| SegmentMetadataDao::destroyGetCache($id_segment, 'translation_disabled'); |
Copilot
AI
Apr 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When disabling a segment, you update DB via setTranslationDisabled() but only destroy the getAll() cache. If SegmentMetadataDao::get($id_segment, 'translation_disabled') was previously cached as empty (TTL=1 week), isSegmentDisabled()'s DB fallback can keep returning "enabled" after its 1h Redis TTL expires. Invalidate the key-specific DAO cache too (e.g. SegmentMetadataDao::destroyCache($id_segment, 'translation_disabled')) when writing the flag.
| SegmentMetadataDao::setTranslationDisabled($id_segment); | |
| SegmentMetadataDao::setTranslationDisabled($id_segment); | |
| SegmentMetadataDao::destroyCache($id_segment, 'translation_disabled'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| use Controller\Abstracts\KleinController; | ||
| use Controller\API\Commons\Validators\LoginValidator; | ||
| use Controller\Traits\SegmentDisabledTrait; | ||
| use Exception; | ||
| use Matecat\SubFiltering\MateCatFilter; | ||
| use Model\Analysis\Constants\ConstantsInterface; | ||
|
|
@@ -29,6 +30,7 @@ | |
|
|
||
| class SegmentAnalysisController extends KleinController | ||
| { | ||
| use SegmentDisabledTrait; | ||
|
|
||
| const int MAX_PER_PAGE = 200; | ||
|
|
||
|
|
@@ -346,6 +348,8 @@ private function formatSegment( | |
| $metadataDao->getProjectStaticSubfilteringCustomHandlers($jobStruct->id_project) | ||
| ); | ||
|
|
||
| $disabled = $this->isSegmentDisabled($segmentForAnalysis->id_job, $segmentForAnalysis->id); | ||
|
|
||
| return [ | ||
| 'id_segment' => (int)$segmentForAnalysis->id, | ||
| 'id_chunk' => (int)$segmentForAnalysis->id_job, | ||
|
|
@@ -366,6 +370,7 @@ private function formatSegment( | |
| 'notes' => (!empty($notesAggregate[$segmentForAnalysis->id]) ? $notesAggregate[$segmentForAnalysis->id] : []), | ||
| 'status' => $this->getStatusObject($segmentForAnalysis), | ||
| 'last_edit' => ($segmentForAnalysis->last_edit !== null) ? date(DATE_ATOM, strtotime($segmentForAnalysis->last_edit)) : null, | ||
| 'disabled' => $disabled, | ||
|
Comment on lines
351
to
+373
|
||
| ]; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.