Avoid fetching from database when only accessing primary key

master
Sven Slootweg 10 months ago
parent 7e619deb22
commit 35b0c5b09e

@ -156,10 +156,15 @@ module.exports = {
types: {
[typeName]: async function({ id }) {
let normalFields = fieldNames.map((name) => {
return [ name, async (_, { dlayerKnexTable }) => {
let record = await dlayerKnexTable.load(id);
return record[name];
}];
if (name === primaryKey) {
// No point making a trip to the database if all we need is an ID we already have
return [ name, id ];
} else {
return [ name, async (_, { dlayerKnexTable }) => {
let record = await dlayerKnexTable.load(id);
return record[name];
}];
}
});
let relationFields = [];

Loading…
Cancel
Save