From 06b82aa3989d13ff3d55381242c22d5fc5a27dfb Mon Sep 17 00:00:00 2001 From: Federico Ricciuti Date: Mon, 13 Jan 2025 11:33:19 +0100 Subject: [PATCH] Fix: duplicate calls to getContributions (#3757) * Gix getContributions requests * Fix: delete the call to getContribution when opening the tab * Fix duplicate glossary calls --- inc/task_manager_config.ini.sample | 6 +++ .../cat_source/es6/actions/CatToolActions.js | 4 +- .../cat_source/es6/actions/SegmentActions.js | 8 ++-- .../SegmentFooterTabGlossary.js | 8 ---- .../segments/utils/translationMatches.js | 14 +++---- .../CrossLanguagesMatches.js | 38 ++++++++++--------- .../TranslationMemoryGlossaryTab/TMKeyRow.js | 3 +- .../TranslationMemoryGlossaryTab.js | 36 ++++++++++++------ .../es6/constants/CatToolConstants.js | 1 - .../js/cat_source/es6/constants/Constants.js | 2 + .../js/cat_source/es6/stores/CatToolStore.js | 6 --- 11 files changed, 65 insertions(+), 61 deletions(-) diff --git a/inc/task_manager_config.ini.sample b/inc/task_manager_config.ini.sample index b8aca54dd9..e0ba93c1f9 100644 --- a/inc/task_manager_config.ini.sample +++ b/inc/task_manager_config.ini.sample @@ -38,6 +38,12 @@ P4[max_executors] = 5 MAIL[queue_name] = "mail_queue" MAIL[max_executors] = 0 +;;################################### +;;##### Propagation ##### +;;################################### +PROPAGATION[queue_name] = "propagation" +PROPAGATION[max_executors] = 1 + ;;############################## ;;##### Key Name setContribution ##### ;;############################## diff --git a/public/js/cat_source/es6/actions/CatToolActions.js b/public/js/cat_source/es6/actions/CatToolActions.js index 6339e51bab..f9d48debe6 100644 --- a/public/js/cat_source/es6/actions/CatToolActions.js +++ b/public/js/cat_source/es6/actions/CatToolActions.js @@ -265,9 +265,7 @@ let CatToolActions = { }) }, onTMKeysChangeStatus: () => { - AppDispatcher.dispatch({ - actionType: CatToolConstants.ON_TM_KEYS_CHANGE_STATUS, - }) + CatToolActions.retrieveJobKeys(true) }, setHaveKeysGlossary: (value) => { AppDispatcher.dispatch({ diff --git a/public/js/cat_source/es6/actions/SegmentActions.js b/public/js/cat_source/es6/actions/SegmentActions.js index b837c1ba5d..4f77a0143c 100644 --- a/public/js/cat_source/es6/actions/SegmentActions.js +++ b/public/js/cat_source/es6/actions/SegmentActions.js @@ -1130,10 +1130,10 @@ const SegmentActions = { }) }, - getContributions: function (sid, multiMatchLangs) { - TranslationMatches.getContribution(sid, 0, multiMatchLangs) - TranslationMatches.getContribution(sid, 1, multiMatchLangs) - TranslationMatches.getContribution(sid, 2, multiMatchLangs) + getContributions: function (sid, multiMatchLangs, force) { + TranslationMatches.getContribution(sid, 0, multiMatchLangs, force) + TranslationMatches.getContribution(sid, 1, multiMatchLangs, force) + TranslationMatches.getContribution(sid, 2, multiMatchLangs, force) }, getContribution: function (sid, multiMatchLangs, force) { diff --git a/public/js/cat_source/es6/components/segments/SegmentFooterTabGlossary/SegmentFooterTabGlossary.js b/public/js/cat_source/es6/components/segments/SegmentFooterTabGlossary/SegmentFooterTabGlossary.js index 93cc8c9d86..23a3a97684 100644 --- a/public/js/cat_source/es6/components/segments/SegmentFooterTabGlossary/SegmentFooterTabGlossary.js +++ b/public/js/cat_source/es6/components/segments/SegmentFooterTabGlossary/SegmentFooterTabGlossary.js @@ -232,10 +232,6 @@ export const SegmentFooterTabGlossary = ({ SegmentStore.addListener(SegmentConstants.CHANGE_GLOSSARY, addGlossaryItem) CatToolStore.addListener(CatToolConstants.UPDATE_DOMAINS, setDomains) CatToolStore.addListener(CatToolConstants.UPDATE_TM_KEYS, setJobTmKeys) - CatToolStore.addListener( - CatToolConstants.ON_TM_KEYS_CHANGE_STATUS, - refreshGlossary, - ) CatToolStore.addListener( CatToolConstants.HAVE_KEYS_GLOSSARY, onReceiveHaveKeysGlossary, @@ -260,10 +256,6 @@ export const SegmentFooterTabGlossary = ({ ) CatToolStore.removeListener(CatToolConstants.UPDATE_DOMAINS, setDomains) CatToolStore.removeListener(CatToolConstants.UPDATE_TM_KEYS, setJobTmKeys) - CatToolStore.removeListener( - CatToolConstants.ON_TM_KEYS_CHANGE_STATUS, - refreshGlossary, - ) CatToolStore.removeListener( CatToolConstants.HAVE_KEYS_GLOSSARY, onReceiveHaveKeysGlossary, diff --git a/public/js/cat_source/es6/components/segments/utils/translationMatches.js b/public/js/cat_source/es6/components/segments/utils/translationMatches.js index 567cb135fb..71959c1a33 100644 --- a/public/js/cat_source/es6/components/segments/utils/translationMatches.js +++ b/public/js/cat_source/es6/components/segments/utils/translationMatches.js @@ -120,12 +120,13 @@ let TranslationMatches = { }) if (!currentSegment) return - + //If segment locked or ICE if (SegmentUtils.isIceSegment(currentSegment) && !currentSegment.unlocked) { SegmentActions.addClassToSegment(currentSegment.sid, 'loaded') return Promise.resolve() } let callNewContributions = force + //Check similar segments if ( SegmentStore.lastTranslatedSegmentId && SegmentStore.getSegmentByIdToJS(SegmentStore.lastTranslatedSegmentId) @@ -147,6 +148,7 @@ let TranslationMatches = { callNewContributions = areSimilar || isEqual || force } + //If the segment already has contributions and is not similar to the last translated if ( currentSegment.contributions && currentSegment.contributions.matches.length > 0 && @@ -165,19 +167,15 @@ let TranslationMatches = { return Promise.resolve() } const id_segment_original = currentSegment.original_sid - const nextUntranslated = SegmentStore.getNextSegment({ - current_sid: id_segment_original, - status: SEGMENTS_STATUS.UNTRANSLATED, - }) const nextSegment = SegmentStore.getNextSegment({ - current_sid: id_segment_original, + current_sid: segmentSid, }) // `next` and `untranslated next` are the same if ( next === 2 && - nextUntranslated && + currentSegment && nextSegment && - nextUntranslated === nextSegment + id_segment_original === nextSegment.sid ) { return Promise.resolve() } diff --git a/public/js/cat_source/es6/components/settingsPanel/Contents/EditorSettingsTab/CrossLanguagesMatches.js b/public/js/cat_source/es6/components/settingsPanel/Contents/EditorSettingsTab/CrossLanguagesMatches.js index 8e7b23c1ea..cb2af59427 100644 --- a/public/js/cat_source/es6/components/settingsPanel/Contents/EditorSettingsTab/CrossLanguagesMatches.js +++ b/public/js/cat_source/es6/components/settingsPanel/Contents/EditorSettingsTab/CrossLanguagesMatches.js @@ -1,11 +1,11 @@ -import React, {useContext, useEffect, useState} from 'react' +import React, {useContext, useEffect, useRef, useState} from 'react' import {Select} from '../../../common/Select' import SegmentActions from '../../../../actions/SegmentActions' import ApplicationStore from '../../../../stores/ApplicationStore' import {ApplicationWrapperContext} from '../../../common/ApplicationWrapper' import {isEqual} from 'lodash' - -const METADATA_KEY = 'cross_language_matches' +import SegmentStore from '../../../../stores/SegmentStore' +import {METADATA_KEY} from '../../../../constants/Constants' export const CrossLanguagesMatches = () => { const {userInfo, setUserMetadataKey} = useContext(ApplicationWrapperContext) @@ -24,6 +24,8 @@ export const CrossLanguagesMatches = () => { languages.find((lang) => lang.id === multiMatchLangs?.secondary), ) + const isFirstRender = useRef(true) + useEffect(() => { const languages = ApplicationStore.getLanguages().map((lang) => { return {name: lang.name, id: lang.code} @@ -49,6 +51,10 @@ export const CrossLanguagesMatches = () => { }, [multiMatchLangs?.primary, multiMatchLangs?.secondary]) useEffect(() => { + if (isFirstRender.current) { + isFirstRender.current = false + return + } const settings = { primary: activeLang1?.id, secondary: activeLang2?.id, @@ -65,7 +71,11 @@ export const CrossLanguagesMatches = () => { if (SegmentActions.getContribution) { if (settings.primary) { SegmentActions.modifyTabVisibility('multiMatches', true) - SegmentActions.getContribution(UI.currentSegmentId, settings, true) + SegmentActions.getContributions( + SegmentStore.getCurrentSegmentId(), + settings, + true, + ) } else { SegmentActions.modifyTabVisibility('multiMatches', false) SegmentActions.updateAllSegments() @@ -73,12 +83,6 @@ export const CrossLanguagesMatches = () => { } }, [activeLang1, activeLang2, setUserMetadataKey]) - useEffect(() => { - if (!activeLang1) { - setActiveLang2() - } - }, [activeLang1]) - return (
@@ -100,13 +104,13 @@ export const CrossLanguagesMatches = () => { options={languages} activeOption={activeLang1} showSearchBar={true} - onSelect={(option) => - setActiveLang1( - !(activeLang1 && activeLang1.id === option.id) - ? option - : undefined, - ) - } + onSelect={(option) => { + const lang = !(activeLang1 && activeLang1.id === option.id) + ? option + : undefined + setActiveLang1(lang) + if (!lang) setActiveLang2() + }} > {({name, id}) => ({ row: ( diff --git a/public/js/cat_source/es6/components/settingsPanel/Contents/TranslationMemoryGlossaryTab/TMKeyRow.js b/public/js/cat_source/es6/components/settingsPanel/Contents/TranslationMemoryGlossaryTab/TMKeyRow.js index c00783ce66..e57e654983 100644 --- a/public/js/cat_source/es6/components/settingsPanel/Contents/TranslationMemoryGlossaryTab/TMKeyRow.js +++ b/public/js/cat_source/es6/components/settingsPanel/Contents/TranslationMemoryGlossaryTab/TMKeyRow.js @@ -18,7 +18,6 @@ import {ShareResource} from './ShareResource' import {DeleteResource} from './DeleteResource' import {updateTmKey} from '../../../../api/updateTmKey' import ModalsActions from '../../../../actions/ModalsActions' -import ConfirmMessageModal from '../../../modals/ConfirmMessageModal' import {CreateProjectContext} from '../../../createProject/CreateProjectContext' import Earth from '../../../../../../../img/icons/Earth' @@ -200,7 +199,7 @@ export const TMKeyRow = ({row, onExpandRow}) => { .then(() => { setTmKeys((prevState) => prevState.filter(({key}) => key !== row.key)) if (config.is_cattool) { - CatToolActions.onTMKeysChangeStatus() + !row.isActive && CatToolActions.onTMKeysChangeStatus() } else { const templatesInvolved = projectTemplates .filter((template) => template.tm.some(({key}) => key === row.key)) diff --git a/public/js/cat_source/es6/components/settingsPanel/Contents/TranslationMemoryGlossaryTab/TranslationMemoryGlossaryTab.js b/public/js/cat_source/es6/components/settingsPanel/Contents/TranslationMemoryGlossaryTab/TranslationMemoryGlossaryTab.js index 91db222eb5..ff46d16217 100644 --- a/public/js/cat_source/es6/components/settingsPanel/Contents/TranslationMemoryGlossaryTab/TranslationMemoryGlossaryTab.js +++ b/public/js/cat_source/es6/components/settingsPanel/Contents/TranslationMemoryGlossaryTab/TranslationMemoryGlossaryTab.js @@ -7,13 +7,16 @@ import React, { } from 'react' import {SettingsPanelTable} from '../../SettingsPanelTable/SettingsPanelTable' import {SettingsPanelContext} from '../../SettingsPanelContext' +import {ApplicationWrapperContext} from '../../../common/ApplicationWrapper' import {TMKeyRow} from './TMKeyRow' import {TMCreateResourceRow} from './TMCreateResourceRow' +import CatToolActions from '../../../../actions/CatToolActions' +import SegmentActions from '../../../../actions/SegmentActions' +import SegmentStore from '../../../../stores/SegmentStore' import {updateJobKeys} from '../../../../api/updateJobKeys' - import Users from '../../../../../../../img/icons/Users' import AddWide from '../../../../../../../img/icons/AddWide' -import CatToolActions from '../../../../actions/CatToolActions' +import {METADATA_KEY} from '../../../../constants/Constants' const COLUMNS_TABLE_ACTIVE = [ {name: 'Lookup'}, @@ -99,14 +102,9 @@ export const getTmDataStructureToSendServer = ({tmKeys = [], keysOrdered}) => { export const TranslationMemoryGlossaryTabContext = createContext({}) export const TranslationMemoryGlossaryTab = () => { - const { - tmKeys, - setTmKeys, - openLoginModal, - modifyingCurrentTemplate, - currentProjectTemplate, - } = useContext(SettingsPanelContext) - + const {tmKeys, setTmKeys, modifyingCurrentTemplate, currentProjectTemplate} = + useContext(SettingsPanelContext) + const {userInfo} = useContext(ApplicationWrapperContext) const getPublicMatches = currentProjectTemplate.getPublicMatches const isPretranslate100Active = currentProjectTemplate.pretranslate100 const setIsPretranslate100Active = (value) => @@ -184,7 +182,14 @@ export const TranslationMemoryGlossaryTab = () => { updateJobKeys({ getPublicMatches, dataTm: getTmDataStructureToSendServer({tmKeys, keysOrdered}), - }).then(() => CatToolActions.onTMKeysChangeStatus()) + }).then(() => { + CatToolActions.onTMKeysChangeStatus() + SegmentActions.getContributions( + SegmentStore.getCurrentSegmentId(), + userInfo.metadata[METADATA_KEY], + true, + ) + }) } } @@ -328,7 +333,14 @@ export const TranslationMemoryGlossaryTab = () => { updateJobKeys({ getPublicMatches, dataTm: getTmDataStructureToSendServer({tmKeys}), - }).then(() => CatToolActions.onTMKeysChangeStatus()) + }).then(() => { + CatToolActions.onTMKeysChangeStatus() + SegmentActions.getContributions( + SegmentStore.getCurrentSegmentId(), + userInfo.metadata[METADATA_KEY], + true, + ) + }) } } diff --git a/public/js/cat_source/es6/constants/CatToolConstants.js b/public/js/cat_source/es6/constants/CatToolConstants.js index 0d3b9d2051..b117e0b658 100644 --- a/public/js/cat_source/es6/constants/CatToolConstants.js +++ b/public/js/cat_source/es6/constants/CatToolConstants.js @@ -20,7 +20,6 @@ const CatToolConstants = keyMirror({ ON_RENDER: null, UPDATE_TM_KEYS: null, UPDATE_DOMAINS: null, - ON_TM_KEYS_CHANGE_STATUS: null, HAVE_KEYS_GLOSSARY: null, OPEN_SETTINGS_PANEL: null, GET_JOB_METADATA: null, diff --git a/public/js/cat_source/es6/constants/Constants.js b/public/js/cat_source/es6/constants/Constants.js index f4ebff273e..5a2ca7728c 100644 --- a/public/js/cat_source/es6/constants/Constants.js +++ b/public/js/cat_source/es6/constants/Constants.js @@ -36,3 +36,5 @@ export const NUM_CONCORDANCE_RESULTS = 10 export const EMAIL_PATTERN = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ + +export const METADATA_KEY = 'cross_language_matches' diff --git a/public/js/cat_source/es6/stores/CatToolStore.js b/public/js/cat_source/es6/stores/CatToolStore.js index 0413d106cf..172a06c5f9 100644 --- a/public/js/cat_source/es6/stores/CatToolStore.js +++ b/public/js/cat_source/es6/stores/CatToolStore.js @@ -248,12 +248,6 @@ AppDispatcher.register(function (action) { ...action, }) break - case CatToolConstants.ON_TM_KEYS_CHANGE_STATUS: - CatToolActions.retrieveJobKeys(true) - CatToolStore.emitChange(CatToolConstants.ON_TM_KEYS_CHANGE_STATUS, { - ...action, - }) - break case CatToolConstants.HAVE_KEYS_GLOSSARY: CatToolStore.setHaveKeysGlossary(action.value) CatToolStore.emitChange(CatToolConstants.HAVE_KEYS_GLOSSARY, {