Skip to content

Commit

Permalink
Fix: duplicate calls to getContributions (#3757)
Browse files Browse the repository at this point in the history
* Gix getContributions requests

* Fix: delete the call to getContribution when opening the tab

* Fix duplicate glossary calls
  • Loading branch information
riccio82 authored Jan 13, 2025
1 parent 921dfde commit 06b82aa
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 61 deletions.
6 changes: 6 additions & 0 deletions inc/task_manager_config.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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 #####
;;##############################
Expand Down
4 changes: 1 addition & 3 deletions public/js/cat_source/es6/actions/CatToolActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ let CatToolActions = {
})
},
onTMKeysChangeStatus: () => {
AppDispatcher.dispatch({
actionType: CatToolConstants.ON_TM_KEYS_CHANGE_STATUS,
})
CatToolActions.retrieveJobKeys(true)
},
setHaveKeysGlossary: (value) => {
AppDispatcher.dispatch({
Expand Down
8 changes: 4 additions & 4 deletions public/js/cat_source/es6/actions/SegmentActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 &&
Expand All @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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}
Expand All @@ -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,
Expand All @@ -65,20 +71,18 @@ 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()
}
}
}, [activeLang1, activeLang2, setUserMetadataKey])

useEffect(() => {
if (!activeLang1) {
setActiveLang2()
}
}, [activeLang1])

return (
<div className="options-box multi-match">
<div className="option-description">
Expand All @@ -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: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand Down Expand Up @@ -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) =>
Expand Down Expand Up @@ -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,
)
})
}
}

Expand Down Expand Up @@ -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,
)
})
}
}

Expand Down
1 change: 0 additions & 1 deletion public/js/cat_source/es6/constants/CatToolConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions public/js/cat_source/es6/constants/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
6 changes: 0 additions & 6 deletions public/js/cat_source/es6/stores/CatToolStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit 06b82aa

Please sign in to comment.