mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 20:06:08 +01:00
add api.runAsyncOnBackendWithManualTransactionHandling() variant and add toast warnings about improper usage.
This commit is contained in:
@@ -4,12 +4,16 @@ const scriptService = require('../../services/script');
|
||||
const attributeService = require('../../services/attributes');
|
||||
const becca = require('../../becca/becca');
|
||||
const syncService = require('../../services/sync');
|
||||
const sql = require('../../services/sql');
|
||||
|
||||
// The async/await here is very confusing, because the body.script may, but may not be async. If it is async, then we
|
||||
// need to await it and make the complete response including metadata available in a Promise, so that the route detects
|
||||
// this and does result.then().
|
||||
async function exec(req) {
|
||||
try {
|
||||
const {body} = req;
|
||||
|
||||
const result = await scriptService.executeScript(
|
||||
const execute = body => scriptService.executeScript(
|
||||
body.script,
|
||||
body.params,
|
||||
body.startNoteId,
|
||||
@@ -18,6 +22,10 @@ async function exec(req) {
|
||||
body.originEntityId
|
||||
);
|
||||
|
||||
const result = body.transactional
|
||||
? sql.transactional(() => execute(body))
|
||||
: await execute(body);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
executionResult: result,
|
||||
|
||||
Reference in New Issue
Block a user