Hi team,
This issue is linked to the performance issue #1008
Looking for a way to override the default route that gets a list of users, I have found the following code in the doc, and worked from this base:
const params = request.query;
params.searchExtended = '1';
const recordsGetter = new RecordsGetter(models.users);
const users = await recordsGetter.getAll(params);
const usersSerialized = await recordsGetter.serialize(users);
return response.send(usersSerialized);
My need was to add a specific condition when getting the users.
1. First try
I replaced the call to getAll
function by my own construction to get the records.
And, at the end, I called:
const usersSerialized = await recordsGetter.serialize(users);
Problem: When calling the serialize
function, all the smart fields of my associated collections are computed, and are generating performance issues (see #1008)
I looked at the code, and I detected that the fieldsPerModel
property of class recordsGetter
is initialized in getAll
method. Because I cannot call the getAll method, I am getting this described issue.
2. Second try
Then, I tried this code
const recordSerializer = new RecordSerializer({ name: 'users' });
const usersSerialized = await recordSerializer.serialize(users)
Problem: it reproduced the same issue with useless smart fields computations.
Question
Once the users
records are built, what is the right way to serialize them, without generating the smart fields computation issue?
Do you have another solution?
Or would you able to provide a fix to make my proposal(s) work?
Thanks in advance for your help.
My setup:
"database_type": "postgres",
"liana": "forest-express-sequelize",
"liana_version": "6.3.13",
"engine": "nodejs",
"engine_version": "12.13.1",
"framework": "express",
"framework_version": "^4.17.1",
"orm_version": "4.44.4"