mirror of
https://github.com/zadam/trilium.git
synced 2025-02-24 15:05:31 +08:00
"pojoing" backend entity responses to significantly speed up
This commit is contained in:
parent
b381331029
commit
507a0e2e1d
1 changed files with 12 additions and 0 deletions
|
@ -49,6 +49,7 @@ const entityChangesService = require('../services/entity_changes');
|
|||
const csurf = require('csurf');
|
||||
const {createPartialContentHandler} = require("express-partial-content");
|
||||
const rateLimit = require("express-rate-limit");
|
||||
const AbstractEntity = require("../becca/entities/abstract_entity.js");
|
||||
|
||||
const csrfMiddleware = csurf({
|
||||
cookie: true,
|
||||
|
@ -58,6 +59,17 @@ const csrfMiddleware = csurf({
|
|||
function apiResultHandler(req, res, result) {
|
||||
res.setHeader('trilium-max-entity-change-id', entityChangesService.getMaxEntityChangeId());
|
||||
|
||||
if (result instanceof AbstractEntity) {
|
||||
result = result.getPojo();
|
||||
}
|
||||
else if (Array.isArray(result)) {
|
||||
for (const idx in result) {
|
||||
if (result[idx] instanceof AbstractEntity) {
|
||||
result[idx] = result[idx].getPojo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if it's an array and first element is integer then we consider this to be [statusCode, response] format
|
||||
if (Array.isArray(result) && result.length > 0 && Number.isInteger(result[0])) {
|
||||
const [statusCode, response] = result;
|
||||
|
|
Loading…
Reference in a new issue