chore(): Remove default limit from the build query (#9257)

* chore(): Remove default limit from the build query

* rm take: null

* fix tests

* fix tests

* fix db usage

* fix typo

* rm unsused template arg

* fixes

* fixes

* fixes

* fixes

* fixes

* fixes

* fixes
This commit is contained in:
Adrien de Peretti
2024-09-24 16:06:45 +02:00
committed by GitHub
parent 9e711720dd
commit 90d530565b
41 changed files with 549 additions and 224 deletions

View File

@@ -1,5 +1,5 @@
import { DAL, FindConfig } from "@medusajs/types"
import { deduplicate, isDefined, isObject } from "../common"
import { deduplicate, isObject } from "../common"
import { SoftDeletableFilterKey } from "../dal/mikro-orm/mikro-orm-soft-deletable-filter"
@@ -18,33 +18,13 @@ export function buildQuery<T = any, TDto = any>(
const filterFlags: FilterFlags = {}
buildWhere(filters, where, filterFlags)
const primaryKeyFieldArray = isDefined(config.primaryKeyFields)
? !Array.isArray(config.primaryKeyFields)
? [config.primaryKeyFields]
: config.primaryKeyFields
: ["id"]
const whereHasPrimaryKeyFields = primaryKeyFieldArray.some(
(pkField) => !!where[pkField]
)
const defaultLimit = whereHasPrimaryKeyFields ? undefined : 15
delete config.primaryKeyFields
const findOptions: DAL.OptionsQuery<T, any> = {
populate: deduplicate(config.relations ?? []),
fields: config.select as string[],
limit:
(Number.isSafeInteger(config.take) && config.take! >= 0) ||
null === config.take
? config.take ?? undefined
: defaultLimit,
offset:
(Number.isSafeInteger(config.skip) && config.skip! >= 0) ||
null === config.skip
? config.skip ?? undefined
: 0,
limit: (Number.isSafeInteger(config.take) && config.take) || undefined,
offset: (Number.isSafeInteger(config.skip) && config.skip) || undefined,
}
if (config.order) {

View File

@@ -272,9 +272,7 @@ export function MedusaInternalService<
if (input_.selector) {
const entitiesToUpdate = await this.list(
input_.selector,
{
take: null,
},
{},
sharedContext
)
// Create a pair of entity and data to update
@@ -303,7 +301,7 @@ export function MedusaInternalService<
if (keySelectorForDataOnly.$or.length) {
const entitiesToUpdate = await this.list(
keySelectorForDataOnly,
{ take: null },
{},
sharedContext
)