enables lean mongoose queries for all find operations
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const { isValidObjectId } = require('mongoose');
|
||||
const { ValidationError } = require('../errors');
|
||||
const executeAccess = require('../auth/executeAccess');
|
||||
const sanitizeFallbackLocale = require('../localization/sanitizeFallbackLocale');
|
||||
|
||||
async function performFieldOperations(entityConfig, args) {
|
||||
const {
|
||||
@@ -12,10 +13,14 @@ async function performFieldOperations(entityConfig, args) {
|
||||
id,
|
||||
req: {
|
||||
payloadAPI,
|
||||
locale,
|
||||
},
|
||||
overrideAccess,
|
||||
reduceLocales,
|
||||
} = args;
|
||||
|
||||
const fallbackLocale = sanitizeFallbackLocale(req.fallbackLocale);
|
||||
|
||||
const recursivePerformFieldOperations = performFieldOperations.bind(this);
|
||||
|
||||
let depth = 0;
|
||||
@@ -275,6 +280,13 @@ async function performFieldOperations(entityConfig, args) {
|
||||
fields.forEach((field) => {
|
||||
const dataCopy = data;
|
||||
|
||||
if (reduceLocales && field.name && field.localized && locale !== 'all' && typeof data[field.name] === 'object') {
|
||||
let localizedValue = data[field.name][locale];
|
||||
if (typeof localizedValue === 'undefined' && fallbackLocale) localizedValue = data[field.name][fallbackLocale];
|
||||
if (typeof localizedValue === 'undefined') localizedValue = null;
|
||||
dataCopy[field.name] = localizedValue;
|
||||
}
|
||||
|
||||
if (field.type === 'upload') {
|
||||
if (data[field.name] === '') dataCopy[field.name] = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user