Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit ce2a1b7

Browse files
authored
Merge pull request #9 from edx/dsheraz/script-perf-updates
fix: Fix loop inconsistent behavior with async/await in put comments
2 parents 83eb307 + 7fe42ab commit ce2a1b7

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/put_comments.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,28 @@ async function addInstructions(translationStringsData, args) {
101101
if (translationStringsData.length !== 0) {
102102
const resourceIdBaseString = `o:${args.org}:p:${args.project}:r:${args.resource}`;
103103

104-
translationStringsData.forEach(async (value) => {
104+
for (let counter = 0; counter < translationStringsData.length; counter += 1) {
105105
/*
106106
Convert string <hash>|<instructions> into list
107107
Get hash from the first element
108108
Join the remaining list with | as separator to get instructions. This join is done
109109
so that if the instruction string itself contained |, the splitted data length will
110110
be more than 2 and there might be chance of incomplete instruction being added to Transifex.
111111
*/
112+
const value = translationStringsData[counter];
112113
const valueList = value.split("|");
113114
const hash = valueList[0];
114115
const instructions = valueList.slice(1).join("|");
115116
const stringId = `${resourceIdBaseString}:s:${hash}`;
116117
process.stdout.write(`Hash: ${stringId}, Instructions: ${instructions}\n`);
118+
// eslint-disable-next-line no-await-in-loop
117119
await addStringInstructions(stringId, instructions, args.token);
118-
});
120+
process.stdout.write(`Instruction addition for Hash ${stringId} completed\n`);
121+
}
119122
}
120123
}
121124

122-
async function main() {
125+
(async function () {
123126
const args = yargs.argv;
124127
const inputFilePath = `${args.inputFileDirectory}/hashed_data.txt`;
125128
let inputData = [];
@@ -130,8 +133,4 @@ async function main() {
130133
process.stderr.write(`Encountered an error while attempting to open ${inputFilePath}\nError:${error.message}\n`);
131134
}
132135
await addInstructions(inputData, args);
133-
}
134-
135-
(async function () {
136-
await main();
137136
}());

0 commit comments

Comments
 (0)