mirror of
https://github.com/strapi/strapi.git
synced 2025-10-10 07:41:04 +00:00
remove relations populate configuration
This commit is contained in:
parent
bf3c7e6a9d
commit
cea950fd96
@ -13,8 +13,4 @@ module.exports = ({ env }) => ({
|
||||
app: {
|
||||
keys: env.array('APP_KEYS', ['toBeModified1', 'toBeModified2']),
|
||||
},
|
||||
// Receive populated relations in webhook and db lifecycle payloads
|
||||
relations: {
|
||||
populate: true,
|
||||
},
|
||||
});
|
||||
|
@ -26,14 +26,6 @@ const wrapWithEmitEvent = (event, fn) => async (entity, body, model) => {
|
||||
entry: sanitizedEntity,
|
||||
});
|
||||
|
||||
// If relations were populated, load the entity again without populating them,
|
||||
// to avoid performance issues
|
||||
if (isRelationsPopulateEnabled(model)) {
|
||||
return strapi.entityService.findOne(model, entity.id, {
|
||||
populate: getCountDeepPopulate(model),
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
@ -57,18 +49,6 @@ const addCreatedByRolesPopulate = (populate) => {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* When relations.populate is set to true, populated relations
|
||||
* will be passed to the webhook and db lifecycles events. The entity-manager
|
||||
* response will not have the populated relations though.
|
||||
* For performance reasons, it is recommended to set it to false,
|
||||
*/
|
||||
const isRelationsPopulateEnabled = () => {
|
||||
return strapi.config.get('server.relations.populate', false);
|
||||
};
|
||||
|
||||
const getCountDeepPopulate = (uid) => getDeepPopulate(uid, { countMany: true, countOne: true });
|
||||
|
||||
/**
|
||||
* @type {import('./entity-manager').default}
|
||||
*/
|
||||
@ -127,7 +107,6 @@ module.exports = ({ strapi }) => ({
|
||||
async create(body, uid) {
|
||||
const modelDef = strapi.getModel(uid);
|
||||
const publishData = { ...body };
|
||||
const populateRelations = isRelationsPopulateEnabled(uid);
|
||||
|
||||
if (hasDraftAndPublish(modelDef)) {
|
||||
publishData[PUBLISHED_AT_ATTRIBUTE] = null;
|
||||
@ -135,57 +114,45 @@ module.exports = ({ strapi }) => ({
|
||||
|
||||
const params = {
|
||||
data: publishData,
|
||||
populate: populateRelations ? getDeepPopulate(uid, {}) : getCountDeepPopulate(uid),
|
||||
populate: getDeepPopulate(uid, {}),
|
||||
};
|
||||
|
||||
const entity = await strapi.entityService.create(uid, params);
|
||||
|
||||
// If relations were populated, load the entity again without populating them,
|
||||
// to avoid performance issues
|
||||
if (populateRelations) {
|
||||
return strapi.entityService.findOne(uid, entity.id, { populate: getCountDeepPopulate(uid) });
|
||||
}
|
||||
|
||||
return entity;
|
||||
return strapi.entityService.findOne(uid, entity.id, {
|
||||
populate: getDeepPopulate(uid, { countMany: true, countOne: true }),
|
||||
});
|
||||
},
|
||||
|
||||
async update(entity, body, uid) {
|
||||
const publishData = omitPublishedAtField(body);
|
||||
const populateRelations = isRelationsPopulateEnabled(uid);
|
||||
|
||||
const params = {
|
||||
data: publishData,
|
||||
populate: populateRelations ? getDeepPopulate(uid, {}) : getCountDeepPopulate(uid),
|
||||
populate: getDeepPopulate(uid, {}),
|
||||
};
|
||||
|
||||
const updatedEntity = await strapi.entityService.update(uid, entity.id, params);
|
||||
await strapi.entityService.update(uid, entity.id, params);
|
||||
|
||||
// If relations were populated, load the entity again without populating them,
|
||||
// to avoid performance issues
|
||||
if (populateRelations) {
|
||||
return strapi.entityService.findOne(uid, entity.id, { populate: getCountDeepPopulate(uid) });
|
||||
}
|
||||
|
||||
return updatedEntity;
|
||||
return strapi.entityService.findOne(uid, entity.id, {
|
||||
populate: getDeepPopulate(uid, { countMany: true, countOne: true }),
|
||||
});
|
||||
},
|
||||
|
||||
async delete(entity, uid) {
|
||||
let entityToDelete;
|
||||
const populateRelations = isRelationsPopulateEnabled(uid);
|
||||
|
||||
const params = {
|
||||
populate: populateRelations ? getDeepPopulate(uid, {}) : getCountDeepPopulate(uid),
|
||||
populate: getDeepPopulate(uid, {}),
|
||||
};
|
||||
|
||||
if (populateRelations) {
|
||||
entityToDelete = await strapi.entityService.findOne(uid, entity.id, {
|
||||
populate: getCountDeepPopulate(uid),
|
||||
});
|
||||
}
|
||||
const deletedEntity = await strapi.entityService.findOne(uid, entity.id, {
|
||||
populate: getDeepPopulate(uid, { countMany: true, countOne: true }),
|
||||
});
|
||||
|
||||
const deletedEntity = await strapi.entityService.delete(uid, entity.id, params);
|
||||
await strapi.entityService.delete(uid, entity.id, params);
|
||||
|
||||
return entityToDelete || deletedEntity;
|
||||
return deletedEntity;
|
||||
},
|
||||
|
||||
// FIXME: handle relations
|
||||
@ -209,22 +176,17 @@ module.exports = ({ strapi }) => ({
|
||||
);
|
||||
|
||||
const data = { ...body, [PUBLISHED_AT_ATTRIBUTE]: new Date() };
|
||||
const populateRelations = isRelationsPopulateEnabled(uid);
|
||||
|
||||
const params = {
|
||||
data,
|
||||
populate: populateRelations ? getDeepPopulate(uid, {}) : getCountDeepPopulate(uid),
|
||||
populate: getDeepPopulate(uid, {}),
|
||||
};
|
||||
|
||||
const updatedEntity = await strapi.entityService.update(uid, entity.id, params);
|
||||
await strapi.entityService.update(uid, entity.id, params);
|
||||
|
||||
// If relations were populated, load the entity again without populating them,
|
||||
// to avoid performance issues
|
||||
if (populateRelations) {
|
||||
return strapi.entityService.findOne(uid, entity.id, { populate: getCountDeepPopulate(uid) });
|
||||
}
|
||||
|
||||
return updatedEntity;
|
||||
return strapi.entityService.findOne(uid, entity.id, {
|
||||
populate: getDeepPopulate(uid, { countMany: true, countOne: true }),
|
||||
});
|
||||
}),
|
||||
|
||||
unpublish: wrapWithEmitEvent(ENTRY_UNPUBLISH, async (entity, body = {}, uid) => {
|
||||
@ -233,14 +195,17 @@ module.exports = ({ strapi }) => ({
|
||||
}
|
||||
|
||||
const data = { ...body, [PUBLISHED_AT_ATTRIBUTE]: null };
|
||||
const populateRelations = isRelationsPopulateEnabled(uid);
|
||||
|
||||
const params = {
|
||||
data,
|
||||
populate: populateRelations ? getDeepPopulate(uid, {}) : getCountDeepPopulate(uid),
|
||||
populate: getDeepPopulate(uid, {}),
|
||||
};
|
||||
|
||||
return strapi.entityService.update(uid, entity.id, params);
|
||||
await strapi.entityService.update(uid, entity.id, params);
|
||||
|
||||
return strapi.entityService.findOne(uid, entity.id, {
|
||||
populate: getDeepPopulate(uid, { countMany: true, countOne: true }),
|
||||
});
|
||||
}),
|
||||
|
||||
async getNumberOfDraftRelations(id, uid) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user