Merge pull request #28 from boazpoolman/feature/no-limit
feat: Itterate through findMany queries limited with 100pull/29/head
commit
00a2c4af34
|
@ -1,4 +1,4 @@
|
||||||
const { logMessage, sanitizeConfig, dynamicSort } = require('../utils');
|
const { logMessage, sanitizeConfig, dynamicSort, noLimit } = require('../utils');
|
||||||
const difference = require('../utils/getArrayDiff');
|
const difference = require('../utils/getArrayDiff');
|
||||||
|
|
||||||
const ConfigType = class ConfigType {
|
const ConfigType = class ConfigType {
|
||||||
|
@ -40,7 +40,7 @@ const ConfigType = class ConfigType {
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all(this.relations.map(async ({ queryString, parentName }) => {
|
await Promise.all(this.relations.map(async ({ queryString, parentName }) => {
|
||||||
const relations = await strapi.query(queryString).findMany({
|
const relations = await noLimit(strapi.query(queryString), {
|
||||||
where: {
|
where: {
|
||||||
[parentName]: entity.id,
|
[parentName]: entity.id,
|
||||||
},
|
},
|
||||||
|
@ -146,7 +146,7 @@ const ConfigType = class ConfigType {
|
||||||
* @returns {object} Object with key value pairs of configs.
|
* @returns {object} Object with key value pairs of configs.
|
||||||
*/
|
*/
|
||||||
getAllFromDatabase = async () => {
|
getAllFromDatabase = async () => {
|
||||||
const AllConfig = await strapi.query(this.queryString).findMany({ limit: 0 });
|
const AllConfig = await noLimit(strapi.query(this.queryString), {});
|
||||||
const configs = {};
|
const configs = {};
|
||||||
|
|
||||||
await Promise.all(Object.values(AllConfig).map(async (config) => {
|
await Promise.all(Object.values(AllConfig).map(async (config) => {
|
||||||
|
@ -156,7 +156,7 @@ const ConfigType = class ConfigType {
|
||||||
|
|
||||||
const formattedConfig = { ...sanitizeConfig(config) };
|
const formattedConfig = { ...sanitizeConfig(config) };
|
||||||
await Promise.all(this.relations.map(async ({ queryString, relationName, relationSortField, parentName }) => {
|
await Promise.all(this.relations.map(async ({ queryString, relationName, relationSortField, parentName }) => {
|
||||||
const relations = await strapi.query(queryString).findMany({
|
const relations = await noLimit(strapi.query(queryString), {
|
||||||
where: { [parentName]: { [this.uid]: config[this.uid] } },
|
where: { [parentName]: { [this.uid]: config[this.uid] } },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,23 @@ const sanitizeConfig = (config, relation, relationSortField) => {
|
||||||
return config;
|
return config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const noLimit = async (query, parameters, limit = 100) => {
|
||||||
|
let entries = [];
|
||||||
|
const amountOfEntries = await query.count(parameters);
|
||||||
|
|
||||||
|
for (let i = 0; i < (amountOfEntries / limit); i++) {
|
||||||
|
/* eslint-disable-next-line */
|
||||||
|
const chunk = await query.findMany({
|
||||||
|
...parameters,
|
||||||
|
limit: limit,
|
||||||
|
offset: (i * limit),
|
||||||
|
});
|
||||||
|
entries = [...chunk, ...entries];
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getService,
|
getService,
|
||||||
getCoreStore,
|
getCoreStore,
|
||||||
|
@ -72,4 +89,5 @@ module.exports = {
|
||||||
sanitizeConfig,
|
sanitizeConfig,
|
||||||
sortByKeys,
|
sortByKeys,
|
||||||
dynamicSort,
|
dynamicSort,
|
||||||
|
noLimit,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue