[groupBy] Load record within groups (without relations) (#15307)

First step of https://github.com/twentyhq/core-team-issues/issues/1726.
I will handle relations in another PR.
Another ticket is planned to allow for sorting among the records.

When querying records we have set the number of maximum groups to 50,
and of maximum records par group to 10.

<img width="1283" height="798" alt="image"
src="https://github.com/user-attachments/assets/7ffc9805-d715-4017-8030-4f3521e6f741"
/>
This commit is contained in:
Marie
2025-10-24 17:30:57 +02:00
committed by GitHub
parent 822b4d75a4
commit d7bda9576f
19 changed files with 840 additions and 362 deletions
@@ -17,7 +17,34 @@ import {
import { type ObjectMetadataMaps } from 'src/engine/metadata-modules/types/object-metadata-maps';
import { getColumnNameToFieldMetadataIdMap } from 'src/engine/twenty-orm/utils/get-column-name-to-field-metadata-id.util';
const getTargetEntityAndOperationType = (expressionMap: QueryExpressionMap) => {
const getTargetEntityAndOperationType = (
expressionMap: QueryExpressionMap,
):
| {
isSubQuery: true;
mainEntity?: undefined;
operationType?: undefined;
}
| {
isSubQuery?: undefined;
mainEntity: string;
operationType:
| 'select'
| 'insert'
| 'update'
| 'delete'
| 'restore'
| 'soft-delete'
| 'relation';
} => {
const isSubQuery = expressionMap.aliases[0].subQuery;
if (isSubQuery) {
return {
isSubQuery: true, // will bypass permission checks because subQuery permissions will be evaluated when it is executed. This is valid for groupBy with records usecase. If your usecase is different, make sure permission checks are run.
};
}
const mainEntity = expressionMap.aliases[0].metadata.name;
const operationType = expressionMap.queryType;
@@ -181,9 +208,13 @@ export const validateQueryIsPermittedOrThrow = ({
return;
}
const { mainEntity, operationType } =
const { mainEntity, operationType, isSubQuery } =
getTargetEntityAndOperationType(expressionMap);
if (isSubQuery) {
return;
}
const allFieldsSelected = expressionMap.selects.some(
(select) => select.selection === mainEntity,
);