Skip to content

Commit e7e9566

Browse files
committed
add feat
1 parent d21bd03 commit e7e9566

File tree

1 file changed

+54
-15
lines changed

1 file changed

+54
-15
lines changed

src/dashboard/Data/Browser/Browser.react.js

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,24 +1571,63 @@ class Browser extends DashboardView {
15711571
}
15721572

15731573
async confirmExecuteScriptRows(script) {
1574+
const batchSize = script.executionBatchSize || 1;
15741575
try {
1575-
const objects = [];
1576-
Object.keys(this.state.selection).forEach(key =>
1577-
objects.push(Parse.Object.extend(this.props.params.className).createWithoutData(key))
1576+
const objects = Object.keys(this.state.selection).map(key =>
1577+
Parse.Object.extend(this.props.params.className).createWithoutData(key)
15781578
);
1579-
for (const object of objects) {
1580-
const response = await Parse.Cloud.run(
1581-
script.cloudCodeFunction,
1582-
{ object: object.toPointer() },
1583-
{ useMasterKey: true }
1579+
1580+
let totalErrorCount = 0;
1581+
let batchCount = 0;
1582+
const totalBatchCount = Math.ceil(objects.length / batchSize);
1583+
1584+
for (let i = 0; i < objects.length; i += batchSize) {
1585+
batchCount++;
1586+
const batch = objects.slice(i, i + batchSize);
1587+
const promises = batch.map(object =>
1588+
Parse.Cloud.run(
1589+
script.cloudCodeFunction,
1590+
{ object: object.toPointer() },
1591+
{ useMasterKey: true }
1592+
).then(response => ({
1593+
objectId: object.id,
1594+
response,
1595+
})).catch(error => ({
1596+
objectId: object.id,
1597+
error,
1598+
}))
15841599
);
1585-
this.setState(prevState => ({
1586-
processedScripts: prevState.processedScripts + 1,
1587-
}));
1588-
const note =
1589-
(typeof response === 'object' ? JSON.stringify(response) : response) ||
1590-
`Ran script "${script.title}" on "${object.id}".`;
1591-
this.showNote(note);
1600+
1601+
const results = await Promise.all(promises);
1602+
1603+
let batchErrorCount = 0;
1604+
results.forEach(({ objectId, response, error }) => {
1605+
this.setState(prevState => ({
1606+
processedScripts: prevState.processedScripts + 1,
1607+
}));
1608+
1609+
if (error) {
1610+
batchErrorCount += 1;
1611+
const errorMessage = `Error running script "${script.title}" on "${objectId}": ${error.message}`;
1612+
this.showNote(errorMessage, true);
1613+
console.error(errorMessage, error);
1614+
} else {
1615+
const note =
1616+
(typeof response === 'object' ? JSON.stringify(response) : response) ||
1617+
`Ran script "${script.title}" on "${objectId}".`;
1618+
this.showNote(note);
1619+
}
1620+
});
1621+
1622+
totalErrorCount += batchErrorCount;
1623+
1624+
if (objects.length > 1) {
1625+
this.showNote(`Ran script "${script.title}" on ${batch.length} object${batch.length > 0 ? 's' : ''} in batch ${batchCount}/${totalBatchCount} with ${batchErrorCount} errors.`, batchErrorCount > 0);
1626+
}
1627+
}
1628+
1629+
if (objects.length > 1) {
1630+
this.showNote(`Ran script "${script.title}" on ${objects.length} objects in ${batchCount} batches with ${totalErrorCount} errors.`, totalErrorCount > 0);
15921631
}
15931632
this.refresh();
15941633
} catch (e) {

0 commit comments

Comments
 (0)