feat(index): add filterable fields to link definition (#11898)
* feat(index): add filterable fields to link definition * rm comment * break recursion * validate read only links * validate filterable * gql schema array * link parents * isInverse * push id when not present * Fix ciruclar relationships and add tests to ensure proper behaviour (part 1) * log and fallback to entity.alias * cleanup and fixes * cleanup and fixes * cleanup and fixes * fix get attributes * gql type * unit test * array inference * rm only * package.json * pacvkage.json * fix link retrieval on duplicated entity type and aliases + tests * link parents as array * Match only parent entity * rm comment * remove hard coded schema * extend types * unit test * test * types * pagination type * type * fix integration tests * Improve performance of in selection * use @@ to filter property * escape jsonPath * add Event Bus by default * changeset * rm postgres analyze * estimate count * new query * parent aliases * inner query w/ filter and sort relations * address comments --------- Co-authored-by: adrien2p <adrien.deperetti@gmail.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8a3f639f01
commit
b868a4ef4d
@@ -68,37 +68,6 @@ export class PostgresProvider implements IndexTypes.StorageProvider {
|
||||
|
||||
this.schemaObjectRepresentation_ = options.schemaObjectRepresentation
|
||||
this.schemaEntitiesMap_ = options.entityMap
|
||||
|
||||
// Add a new column for each key that can be found in the jsonb data column to perform indexes and query on it.
|
||||
// So far, the execution time is about the same
|
||||
/*;(async () => {
|
||||
const query = [
|
||||
...new Set(
|
||||
Object.keys(this.schemaObjectRepresentation_)
|
||||
.filter(
|
||||
(key) =>
|
||||
![
|
||||
"_serviceNameModuleConfigMap",
|
||||
"_schemaPropertiesMap",
|
||||
].includes(key)
|
||||
)
|
||||
.map((key) => {
|
||||
return this.schemaObjectRepresentation_[key].fields.filter(
|
||||
(field) => !field.includes(".")
|
||||
)
|
||||
})
|
||||
.flat()
|
||||
),
|
||||
].map(
|
||||
(field) =>
|
||||
"ALTER TABLE index_data ADD IF NOT EXISTS " +
|
||||
field +
|
||||
" text GENERATED ALWAYS AS (NEW.data->>'" +
|
||||
field +
|
||||
"') STORED"
|
||||
)
|
||||
await this.manager_.execute(query.join(";"))
|
||||
})()*/
|
||||
}
|
||||
|
||||
async onApplicationStart() {
|
||||
@@ -138,7 +107,7 @@ export class PostgresProvider implements IndexTypes.StorageProvider {
|
||||
const parentAlias = field.split(".")[0]
|
||||
const parentSchemaObjectRepresentation =
|
||||
schemaEntityObjectRepresentation.parents.find(
|
||||
(parent) => parent.ref.alias === parentAlias
|
||||
(parent) => parent.inverseSideProp === parentAlias
|
||||
)
|
||||
|
||||
if (!parentSchemaObjectRepresentation) {
|
||||
@@ -304,7 +273,6 @@ export class PostgresProvider implements IndexTypes.StorageProvider {
|
||||
schema: this.schemaObjectRepresentation_,
|
||||
entityMap: this.schemaEntitiesMap_,
|
||||
knex: connection.getKnex(),
|
||||
rawConfig: config,
|
||||
selector: {
|
||||
select,
|
||||
where,
|
||||
@@ -316,26 +284,30 @@ export class PostgresProvider implements IndexTypes.StorageProvider {
|
||||
keepFilteredEntities,
|
||||
orderBy,
|
||||
},
|
||||
rawConfig: config,
|
||||
requestedFields,
|
||||
})
|
||||
|
||||
const sql = qb.buildQuery({
|
||||
const { sql, sqlCount } = qb.buildQuery({
|
||||
hasPagination,
|
||||
returnIdOnly: !!keepFilteredEntities,
|
||||
hasCount,
|
||||
})
|
||||
|
||||
const resultSet = await manager.execute(sql)
|
||||
const [resultSet, countResult] = await Promise.all([
|
||||
manager.execute(sql),
|
||||
hasCount ? manager.execute(sqlCount!) : null,
|
||||
])
|
||||
|
||||
const resultMetadata: IndexTypes.QueryFunctionReturnPagination | undefined =
|
||||
hasPagination
|
||||
? {
|
||||
count: hasCount
|
||||
? parseInt(resultSet[0]?.count_total ?? 0)
|
||||
? ({
|
||||
estimate_count: hasCount
|
||||
? parseInt(countResult![0]?.estimate_count ?? 0)
|
||||
: undefined,
|
||||
skip,
|
||||
take,
|
||||
}
|
||||
} as IndexTypes.QueryFunctionReturnPagination)
|
||||
: undefined
|
||||
|
||||
if (keepFilteredEntities) {
|
||||
|
||||
Reference in New Issue
Block a user