Hello. I am implementing a filter on a smart field. My code works but I don’t feel that will be able to scale.
This smart field comes from a joint table.
- Table Event
- id : integer
- accountId : integer
- Table Account
- id : integer
- countryFullname : integer
For the moment, my implementation looks like this (on Event collection) :
async function filterOnAccountCountryFullname(context: SmartFieldFiltererFilter, type: string) {
if (context.condition.operator != "blank") {
const parser = new FilterParser({ fields: [] }, "Europe/Paris");
const where = await parser.formatCondition({
field: "countryFullname",
operator: context.condition.operator,
value: context.condition.value,
});
const accounts = await AccountModel.findAll({ attributes: ["id"], where });
return { [type]: { [Op.in]: accounts.map(a => a.id) } };
}
return { [type]: { [Op.or]: [{ [Op.eq]: null }, { [Op.eq]: "" }] } };
}
I encounter some performance issues as the Op.in may contain a lot of data.
Do you have any ideas for a better implementation of this pattern? I would like not to use Op.in and, if possible, load the Accounts when we load the Events.