Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregated optimization changes #2744

Merged
merged 24 commits into from
Mar 20, 2024
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4034445
fix(core): self-referencing relations `Not unique table/alias`
monrostar Mar 15, 2024
16cfc07
perf(core): upgrade sql requests for more performant memory usage wit…
monrostar Mar 15, 2024
469a02b
perf(core): Upgrade EntityHydrator to add more performance to any hyd…
monrostar Mar 15, 2024
10c0798
fix(core): update self-related manual joins with deep eager relations
monrostar Mar 16, 2024
4824d86
chore(core): clean up code
monrostar Mar 16, 2024
5eb6391
fix(core): update test cases for new TestEntities order
monrostar Mar 16, 2024
0750065
feat(core): optimization for assignToChannels method
monrostar Mar 16, 2024
dc463ba
feat(core): fix changes for new getAssignedEntityChannels method
monrostar Mar 16, 2024
4486cd2
Merge branch 'perf/performance-improvement-in-entity-hydrator' into f…
monrostar Mar 16, 2024
949dc54
Merge branch 'perf/optimize-assign-to-channels' into feat/aggregated-prs
monrostar Mar 16, 2024
85821b7
Merge branch 'perf/product-soft-delete-performance-update' into feat/…
monrostar Mar 16, 2024
c376eef
feat(core): add optimization into findOneInChannel and more refactoring
monrostar Mar 16, 2024
661c2e9
perf(core): optimize translatable-saver.ts query to get existingTrans…
monrostar Mar 17, 2024
eaca1c9
fix(core): Added processing of deeply nested relations that lack Reve…
monrostar Mar 17, 2024
11e3904
fix(core): fix condition for tree type of metadata in list-query-builder
monrostar Mar 17, 2024
d1494bd
Merge branch 'minor' into feat/aggregated-prs
monrostar Mar 19, 2024
c92bf6d
feat(core): Added edge case handling with customFields as well as dep…
monrostar Mar 19, 2024
b54f0f0
feat(core): Clean up code and remove joinEagerRelations helper
monrostar Mar 19, 2024
7af0d4a
feat(core): Fix import in the unit test case
monrostar Mar 19, 2024
5f836b9
feat(core): Fix import in the unit test case
monrostar Mar 19, 2024
0dfb4f6
feat(core): Fix condition for tree type of all relation entities
monrostar Mar 19, 2024
8a15a26
chore(core): Code style fixes
monrostar Mar 20, 2024
d6c50d5
docs(core): Update docs for joinTreeRelationsDynamically
monrostar Mar 20, 2024
a444894
chore(core): Remove unused import
monrostar Mar 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(core): fix changes for new getAssignedEntityChannels method
  • Loading branch information
monrostar committed Mar 16, 2024
commit dc463bab761d49a86f80a479338a45afb132ca84
36 changes: 21 additions & 15 deletions packages/core/src/service/services/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ import {
import { DEFAULT_CHANNEL_CODE } from '@vendure/common/lib/shared-constants';
import { ID, PaginatedList, Type } from '@vendure/common/lib/shared-types';
import { unique } from '@vendure/common/lib/unique';
import { FindOneOptions, FindOptionsWhere } from 'typeorm';
import { FindOptionsWhere } from 'typeorm';

import { RelationPaths } from '../../api';
import { RequestContext } from '../../api/common/request-context';
import { ErrorResultUnion, isGraphQlErrorResult } from '../../common/error/error-result';
import {
ChannelNotFoundError,
EntityNotFoundError,
InternalServerError,
UserInputError,
} from '../../common/error/errors';
import { ChannelNotFoundError, EntityNotFoundError, InternalServerError, UserInputError } from '../../common/error/errors';
import { LanguageNotAvailableError } from '../../common/error/generated-graphql-admin-errors';
import { createSelfRefreshingCache, SelfRefreshingCache } from '../../common/self-refreshing-cache';
import { ChannelAware, ListQueryOptions } from '../../common/types/common-types';
Expand Down Expand Up @@ -136,17 +131,28 @@ export class ChannelService {
* @private
*/
private async getAssignedEntityChannels<T extends ChannelAware & VendureEntity>(ctx: RequestContext, entityType: Type<T>, entityId: T['id']): Promise<{ channelId: ID }[]> {
const entityMetadata = this.connection.rawConnection.getMetadata(entityType);
const channelsRelation = entityMetadata.relations.find(r => r.type === Channel);
const repository = this.connection.getRepository(ctx, entityType);

const metadata = repository.metadata;
const channelsRelation = metadata.findRelationWithPropertyPath('channels');

if (!channelsRelation) {
throw new InternalServerError(`Could not find the join table for the channels relation of entity ${entityMetadata.targetName}`);
throw new InternalServerError(`Could not find the channels relation for entity ${metadata.name}`);
}
const junctionColumnName = channelsRelation.joinColumns.find(jc => jc.referencedColumn?.entityMetadata === entityMetadata)?.databaseName;
if (!junctionColumnName) {
throw new InternalServerError(`Could not find the junction column for the channels relation of entity ${entityMetadata.targetName}`);

const junctionTableName = channelsRelation.junctionEntityMetadata?.tableName;
const junctionColumnName = channelsRelation.junctionEntityMetadata?.columns[0].databaseName;
const inverseJunctionColumnName = channelsRelation.junctionEntityMetadata?.inverseColumns[0].databaseName;

if (!junctionTableName || !junctionColumnName || !inverseJunctionColumnName) {
throw new InternalServerError(`Could not find necessary join table information for the channels relation of entity ${metadata.name}`);
}
const sqlToGetAssignedChannelIds = `SELECT "channelId" as "channelId" FROM "${channelsRelation?.joinTableName}" WHERE "${junctionColumnName}" = $1`;
return await this.connection.getRepository(ctx, entityType).query(sqlToGetAssignedChannelIds, [entityId]);

return await this.connection.getRepository(ctx, entityType).createQueryBuilder()
.select(`channel.${inverseJunctionColumnName}`, 'channelId')
.from(junctionTableName, 'channel')
.where(`channel.${junctionColumnName} = :entityId`, { entityId })
.execute();
}

/**
Expand Down
Loading