Browse Source

refactor(core): Remove unnecessary metadaModifiers addForeignKeyIndices function (#2332)

Alexis Vigoureux 2 years ago
parent
commit
bdab886ab3

+ 0 - 32
packages/core/src/config/entity-metadata/add-foreign-key-indices.ts

@@ -1,32 +0,0 @@
-import { Index } from 'typeorm';
-import { MetadataArgsStorage } from 'typeorm/metadata-args/MetadataArgsStorage';
-
-import { StockMovement } from '../../entity/stock-movement/stock-movement.entity';
-
-import { EntityMetadataModifier } from './entity-metadata-modifier';
-
-/**
- * @description
- * Dynamically adds `@Index()` metadata to all many-to-one relations. These are already added
- * by default in MySQL/MariaDB, but not in Postgres. So this modification can lead to improved
- * performance with Postgres - especially when dealing with large numbers of products, orders etc.
- *
- * See https://github.com/vendure-ecommerce/vendure/issues/1502
- *
- * TODO: In v2 we will add the Index to all relations manually, this making this redundant.
- */
-export const addForeignKeyIndices: EntityMetadataModifier = (metadata: MetadataArgsStorage) => {
-    for (const relationMetadata of metadata.relations) {
-        const { relationType, target } = relationMetadata;
-        if (relationType === 'many-to-one') {
-            const embeddedIn = metadata.embeddeds.find(e => e.type() === relationMetadata.target)?.target;
-            const targetClass = (embeddedIn ?? target) as FunctionConstructor;
-            if (typeof targetClass === 'function') {
-                const instance = new targetClass();
-                if (!(instance instanceof StockMovement)) {
-                    Index()(instance, relationMetadata.propertyName);
-                }
-            }
-        }
-    }
-};

+ 0 - 1
packages/core/src/config/index.ts

@@ -29,7 +29,6 @@ export * from './entity/bigint-money-strategy';
 export * from './entity/entity-id-strategy';
 export * from './entity/money-strategy';
 export * from './entity/uuid-id-strategy';
-export * from './entity-metadata/add-foreign-key-indices';
 export * from './entity-metadata/entity-metadata-modifier';
 export * from './fulfillment/default-fulfillment-process';
 export * from './fulfillment/fulfillment-handler';

+ 0 - 4
packages/dev-server/load-testing/load-test-config.ts

@@ -1,7 +1,6 @@
 /* eslint-disable no-console */
 import { AssetServerPlugin } from '@vendure/asset-server-plugin';
 import {
-    addForeignKeyIndices,
     defaultConfig,
     DefaultJobQueuePlugin,
     DefaultLogger,
@@ -59,9 +58,6 @@ export function getLoadTestConfig(
             ...connectionOptions,
             synchronize: true,
         },
-        entityOptions: {
-            metadataModifiers: [addForeignKeyIndices],
-        },
         authOptions: {
             tokenMethod,
             requireVerification: false,