Quellcode durchsuchen

Merge branch 'master' into minor

Michael Bromley vor 4 Jahren
Ursprung
Commit
997e1f8065

+ 23 - 0
CHANGELOG.md

@@ -1,3 +1,26 @@
+## <small>1.2.2 (2021-09-28)</small>
+
+
+#### Perf
+
+* **core** Cache certain field resolvers to avoid duplicated DB calls ([13697c3](https://github.com/vendure-ecommerce/vendure/commit/13697c3)), closes [#1119](https://github.com/vendure-ecommerce/vendure/issues/1119)
+
+#### Fixes
+
+* **admin-ui** Do not cache active admin details between logins ([20b4b04](https://github.com/vendure-ecommerce/vendure/commit/20b4b04)), closes [#1099](https://github.com/vendure-ecommerce/vendure/issues/1099)
+* **admin-ui** Use correct order total on Customer detail page ([ddc2b0a](https://github.com/vendure-ecommerce/vendure/commit/ddc2b0a))
+* **core**  Fix wrong event type when a variant is created (#1102) ([cc45254](https://github.com/vendure-ecommerce/vendure/commit/cc45254)), closes [#1102](https://github.com/vendure-ecommerce/vendure/issues/1102) [#1095](https://github.com/vendure-ecommerce/vendure/issues/1095)
+* **core** Add missing logging & docs to DefaultJobQueuePlugin ([423f307](https://github.com/vendure-ecommerce/vendure/commit/423f307))
+* **core** Fix collection update event generation (#1114) ([6e7e864](https://github.com/vendure-ecommerce/vendure/commit/6e7e864)), closes [#1114](https://github.com/vendure-ecommerce/vendure/issues/1114) [#1015](https://github.com/vendure-ecommerce/vendure/issues/1015)
+* **core** Fix updating customer email with no NativeAuth configured ([f6d3a52](https://github.com/vendure-ecommerce/vendure/commit/f6d3a52)), closes [#1092](https://github.com/vendure-ecommerce/vendure/issues/1092)
+* **core** Gracefully handle errors when populating initial data ([36c15b2](https://github.com/vendure-ecommerce/vendure/commit/36c15b2))
+* **core** Return correct timestamp values for translated entities ([ded49c4](https://github.com/vendure-ecommerce/vendure/commit/ded49c4)), closes [#1101](https://github.com/vendure-ecommerce/vendure/issues/1101)
+* **core** Soft-delete variants when a product is soft-deleted ([ff1ae90](https://github.com/vendure-ecommerce/vendure/commit/ff1ae90)), closes [#1096](https://github.com/vendure-ecommerce/vendure/issues/1096)
+* **elasticsearch-plugin** Elasticsearch Cloud auth is not set during re-indexing (#1108) ([e40fc1c](https://github.com/vendure-ecommerce/vendure/commit/e40fc1c)), closes [#1108](https://github.com/vendure-ecommerce/vendure/issues/1108) [#1106](https://github.com/vendure-ecommerce/vendure/issues/1106)
+* **email-plugin** Correctly register failed email sending, add retry ([f50708a](https://github.com/vendure-ecommerce/vendure/commit/f50708a))
+* **job-queue-plugin** Add missing logging & backoff settings ([6f7cc34](https://github.com/vendure-ecommerce/vendure/commit/6f7cc34))
+* **job-queue-plugin** Fix redis connection to remote hosts ([9e36873](https://github.com/vendure-ecommerce/vendure/commit/9e36873)), closes [#1097](https://github.com/vendure-ecommerce/vendure/issues/1097)
+
 ## <small>1.2.1 (2021-09-15)</small>
 
 

+ 1 - 1
lerna.json

@@ -2,7 +2,7 @@
   "packages": [
     "packages/*"
   ],
-  "version": "1.2.1",
+  "version": "1.2.2",
   "npmClient": "yarn",
   "useWorkspaces": true,
   "command": {

+ 3 - 3
packages/admin-ui-plugin/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@vendure/admin-ui-plugin",
-  "version": "1.2.1",
+  "version": "1.2.2",
   "main": "lib/index.js",
   "types": "lib/index.d.ts",
   "files": [
@@ -21,8 +21,8 @@
   "devDependencies": {
     "@types/express": "^4.17.8",
     "@types/fs-extra": "^9.0.1",
-    "@vendure/common": "^1.2.1",
-    "@vendure/core": "^1.2.1",
+    "@vendure/common": "^1.2.2",
+    "@vendure/core": "^1.2.2",
     "express": "^4.17.1",
     "rimraf": "^3.0.2",
     "typescript": "4.3.5"

+ 2 - 2
packages/admin-ui/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@vendure/admin-ui",
-  "version": "1.2.1",
+  "version": "1.2.2",
   "license": "MIT",
   "scripts": {
     "ng": "ng",
@@ -39,7 +39,7 @@
     "@ng-select/ng-select": "^7.2.0",
     "@ngx-translate/core": "^13.0.0",
     "@ngx-translate/http-loader": "^6.0.0",
-    "@vendure/common": "^1.2.1",
+    "@vendure/common": "^1.2.2",
     "@webcomponents/custom-elements": "^1.4.3",
     "apollo-angular": "^2.4.0",
     "apollo-upload-client": "^14.1.3",

+ 1 - 1
packages/admin-ui/src/lib/core/src/common/version.ts

@@ -1,2 +1,2 @@
 // Auto-generated by the set-version.js script.
-export const ADMIN_UI_VERSION = '1.2.1';
+export const ADMIN_UI_VERSION = '1.2.2';

+ 3 - 3
packages/asset-server-plugin/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@vendure/asset-server-plugin",
-  "version": "1.2.1",
+  "version": "1.2.2",
   "main": "lib/index.js",
   "types": "lib/index.d.ts",
   "files": [
@@ -24,8 +24,8 @@
     "@types/fs-extra": "^9.0.8",
     "@types/node-fetch": "^2.5.8",
     "@types/sharp": "^0.27.1",
-    "@vendure/common": "^1.2.1",
-    "@vendure/core": "^1.2.1",
+    "@vendure/common": "^1.2.2",
+    "@vendure/core": "^1.2.2",
     "aws-sdk": "^2.856.0",
     "express": "^4.17.1",
     "node-fetch": "^2.6.1",

+ 1 - 1
packages/common/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@vendure/common",
-  "version": "1.2.1",
+  "version": "1.2.2",
   "main": "index.js",
   "license": "MIT",
   "scripts": {

+ 2 - 2
packages/core/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@vendure/core",
-  "version": "1.2.1",
+  "version": "1.2.2",
   "description": "A modern, headless ecommerce framework",
   "repository": {
     "type": "git",
@@ -49,7 +49,7 @@
     "@nestjs/testing": "7.6.17",
     "@nestjs/typeorm": "7.1.5",
     "@types/fs-extra": "^9.0.1",
-    "@vendure/common": "^1.2.1",
+    "@vendure/common": "^1.2.2",
     "apollo-server-express": "2.24.1",
     "bcrypt": "^5.0.0",
     "body-parser": "^1.19.0",

+ 3 - 1
packages/core/src/api/api-internal-modules.ts

@@ -1,5 +1,6 @@
 import { Module } from '@nestjs/common';
 
+import { CacheModule } from '../cache/cache.module';
 import { ConfigModule } from '../config/config.module';
 import { DataImportModule } from '../data-import/data-import.module';
 import { JobQueueModule } from '../job-queue/job-queue.module';
@@ -152,10 +153,11 @@ export const adminEntityResolvers = [
  * one API module.
  */
 @Module({
-    imports: [ConfigModule, ServiceModule.forRoot()],
+    imports: [ConfigModule, ServiceModule.forRoot(), CacheModule],
     providers: [IdCodecService, ConfigurableOperationCodec, CustomFieldRelationResolverService],
     exports: [
         IdCodecService,
+        CacheModule,
         ConfigModule,
         ConfigurableOperationCodec,
         CustomFieldRelationResolverService,

+ 5 - 1
packages/core/src/api/resolvers/entity/facet-entity.resolver.ts

@@ -1,5 +1,6 @@
 import { Parent, ResolveField, Resolver } from '@nestjs/graphql';
 
+import { RequestContextCacheService } from '../../../cache/request-context-cache.service';
 import { FacetValue } from '../../../entity/facet-value/facet-value.entity';
 import { Facet } from '../../../entity/facet/facet.entity';
 import { LocaleStringHydrator } from '../../../service/helpers/locale-string-hydrator/locale-string-hydrator';
@@ -12,6 +13,7 @@ export class FacetEntityResolver {
     constructor(
         private facetValueService: FacetValueService,
         private localeStringHydrator: LocaleStringHydrator,
+        private requestContextCache: RequestContextCacheService,
     ) {}
 
     @ResolveField()
@@ -24,6 +26,8 @@ export class FacetEntityResolver {
         if (facet.values) {
             return facet.values;
         }
-        return this.facetValueService.findByFacetId(ctx, facet.id);
+        return this.requestContextCache.get(ctx, `FacetEntityResolver.values(${facet.id})`, () =>
+            this.facetValueService.findByFacetId(ctx, facet.id),
+        );
     }
 }

+ 9 - 2
packages/core/src/api/resolvers/entity/facet-value-entity.resolver.ts

@@ -1,5 +1,6 @@
 import { Parent, ResolveField, Resolver } from '@nestjs/graphql';
 
+import { RequestContextCacheService } from '../../../cache/request-context-cache.service';
 import { FacetValue } from '../../../entity/facet-value/facet-value.entity';
 import { Facet } from '../../../entity/facet/facet.entity';
 import { LocaleStringHydrator } from '../../../service/helpers/locale-string-hydrator/locale-string-hydrator';
@@ -9,7 +10,11 @@ import { Ctx } from '../../decorators/request-context.decorator';
 
 @Resolver('FacetValue')
 export class FacetValueEntityResolver {
-    constructor(private facetService: FacetService, private localeStringHydrator: LocaleStringHydrator) {}
+    constructor(
+        private facetService: FacetService,
+        private localeStringHydrator: LocaleStringHydrator,
+        private requestContextCache: RequestContextCacheService,
+    ) {}
 
     @ResolveField()
     name(@Ctx() ctx: RequestContext, @Parent() facetValue: FacetValue): Promise<string> {
@@ -21,6 +26,8 @@ export class FacetValueEntityResolver {
         if (facetValue.facet) {
             return facetValue.facet;
         }
-        return this.facetService.findByFacetValueId(ctx, facetValue.id);
+        return this.requestContextCache.get(ctx, `FacetValueEntityResolver.facet(${facetValue.id})`, () =>
+            this.facetService.findByFacetValueId(ctx, facetValue.id),
+        );
     }
 }

+ 0 - 1
packages/core/src/api/resolvers/entity/product-entity.resolver.ts

@@ -82,7 +82,6 @@ export class ProductEntityResolver {
         @Ctx() ctx: RequestContext,
         @Parent() product: Product,
     ): Promise<Array<Translated<ProductOptionGroup>>> {
-        const a = info;
         return this.productOptionGroupService.getOptionGroupsByProductId(ctx, product.id);
     }
 

+ 5 - 1
packages/core/src/api/resolvers/entity/product-option-entity.resolver.ts

@@ -1,6 +1,7 @@
 import { Parent, ResolveField, Resolver } from '@nestjs/graphql';
 import { Permission } from '@vendure/common/lib/generated-types';
 
+import { RequestContextCacheService } from '../../../cache/request-context-cache.service';
 import { Translated } from '../../../common/types/locale-types';
 import { assertFound } from '../../../common/utils';
 import { ProductOptionGroup } from '../../../entity/product-option-group/product-option-group.entity';
@@ -16,6 +17,7 @@ export class ProductOptionEntityResolver {
     constructor(
         private productOptionGroupService: ProductOptionGroupService,
         private localeStringHydrator: LocaleStringHydrator,
+        private requestContextCache: RequestContextCacheService,
     ) {}
 
     @ResolveField()
@@ -32,6 +34,8 @@ export class ProductOptionEntityResolver {
         if (option.group) {
             return option.group;
         }
-        return assertFound(this.productOptionGroupService.findOne(ctx, option.groupId));
+        return this.requestContextCache.get(ctx, `ProductOptionEntityResolver.group(${option.groupId})`, () =>
+            assertFound(this.productOptionGroupService.findOne(ctx, option.groupId)),
+        );
     }
 }

+ 7 - 1
packages/core/src/api/resolvers/entity/product-variant-entity.resolver.ts

@@ -3,6 +3,7 @@ import { CurrencyCode, StockMovementListOptions } from '@vendure/common/lib/gene
 import { DEFAULT_CHANNEL_CODE } from '@vendure/common/lib/shared-constants';
 import { PaginatedList } from '@vendure/common/lib/shared-types';
 
+import { RequestContextCacheService } from '../../../cache/request-context-cache.service';
 import { Translated } from '../../../common/types/locale-types';
 import { idsAreEqual } from '../../../common/utils';
 import { Asset, Channel, FacetValue, Product, ProductOption, TaxRate } from '../../../entity';
@@ -23,6 +24,7 @@ export class ProductVariantEntityResolver {
         private productVariantService: ProductVariantService,
         private assetService: AssetService,
         private localeStringHydrator: LocaleStringHydrator,
+        private requestContextCache: RequestContextCacheService,
     ) {}
 
     @ResolveField()
@@ -67,7 +69,11 @@ export class ProductVariantEntityResolver {
         if (productVariant.product) {
             return productVariant.product;
         }
-        return this.productVariantService.getProductForVariant(ctx, productVariant);
+        return this.requestContextCache.get(
+            ctx,
+            `ProductVariantEntityResolver.product(${productVariant.productId})`,
+            () => this.productVariantService.getProductForVariant(ctx, productVariant),
+        );
     }
 
     @ResolveField()

+ 27 - 9
packages/core/src/service/services/collection.service.ts

@@ -44,7 +44,7 @@ import { AssetService } from './asset.service';
 import { ChannelService } from './channel.service';
 import { FacetValueService } from './facet-value.service';
 
-type ApplyCollectionFiltersJobData = { ctx: SerializedRequestContext; collectionIds: ID[] };
+type ApplyCollectionFiltersJobData = { ctx: SerializedRequestContext; collectionIds: ID[]; applyToChangedVariantsOnly?: boolean; };
 
 @Injectable()
 export class CollectionService implements OnModuleInit {
@@ -64,7 +64,8 @@ export class CollectionService implements OnModuleInit {
         private slugValidator: SlugValidator,
         private configArgService: ConfigArgService,
         private customFieldRelationService: CustomFieldRelationService,
-    ) {}
+    ) {
+    }
 
     async onModuleInit() {
         const productEvents$ = this.eventBus.ofType(ProductEvent);
@@ -99,7 +100,7 @@ export class CollectionService implements OnModuleInit {
                     }
                     completed++;
                     if (collection) {
-                        const affectedVariantIds = await this.applyCollectionFiltersInternal(collection);
+                        const affectedVariantIds = await this.applyCollectionFiltersInternal(collection, job.data.applyToChangedVariantsOnly);
                         job.setProgress(Math.ceil((completed / job.data.collectionIds.length) * 100));
                         this.eventBus.publish(
                             new CollectionModificationEvent(ctx, collection, affectedVariantIds),
@@ -362,7 +363,11 @@ export class CollectionService implements OnModuleInit {
             await this.applyFiltersQueue.add({
                 ctx: ctx.serialize(),
                 collectionIds: [collection.id],
+                applyToChangedVariantsOnly: false,
             });
+        } else {
+            const affectedVariantIds = await this.getCollectionProductVariantIds(collection);
+            this.eventBus.publish(new CollectionModificationEvent(ctx, collection, affectedVariantIds));
         }
         return assertFound(this.findOne(ctx, collection.id));
     }
@@ -430,8 +435,13 @@ export class CollectionService implements OnModuleInit {
 
     /**
      * Applies the CollectionFilters
+     *
+     * If applyToChangedVariantsOnly (default: true) is true, than apply collection job will process only changed variants
+     * If applyToChangedVariantsOnly (default: true) is false, than apply collection job will process all variants
+     * This param is used when we update collection and collection filters are changed to update all
+     * variants (because other attributes of collection can be changed https://github.com/vendure-ecommerce/vendure/issues/1015)
      */
-    private async applyCollectionFiltersInternal(collection: Collection): Promise<ID[]> {
+    private async applyCollectionFiltersInternal(collection: Collection, applyToChangedVariantsOnly = true): Promise<ID[]> {
         const ancestorFilters = await this.getAncestors(collection.id).then(ancestors =>
             ancestors.reduce(
                 (filters, c) => [...filters, ...(c.filters || [])],
@@ -460,11 +470,19 @@ export class CollectionService implements OnModuleInit {
         }
         const preIdsSet = new Set(preIds);
         const postIdsSet = new Set(postIds);
-        const difference = [
-            ...preIds.filter(id => !postIdsSet.has(id)),
-            ...postIds.filter(id => !preIdsSet.has(id)),
-        ];
-        return difference;
+
+        if (applyToChangedVariantsOnly) {
+            return [
+                ...preIds.filter(id => !postIdsSet.has(id)),
+                ...postIds.filter(id => !preIdsSet.has(id)),
+            ];
+        } else {
+            return [
+                ...preIds.filter(id => !postIdsSet.has(id)),
+                ...postIds,
+            ];
+        }
+
     }
 
     /**

+ 3 - 3
packages/create/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@vendure/create",
-  "version": "1.2.1",
+  "version": "1.2.2",
   "license": "MIT",
   "bin": {
     "create": "./index.js"
@@ -28,13 +28,13 @@
     "@types/handlebars": "^4.1.0",
     "@types/listr": "^0.14.2",
     "@types/semver": "^6.2.2",
-    "@vendure/core": "^1.2.1",
+    "@vendure/core": "^1.2.2",
     "rimraf": "^3.0.2",
     "ts-node": "^10.2.1",
     "typescript": "4.3.5"
   },
   "dependencies": {
-    "@vendure/common": "^1.2.1",
+    "@vendure/common": "^1.2.2",
     "chalk": "^4.1.0",
     "commander": "^7.1.0",
     "cross-spawn": "^7.0.3",

+ 9 - 9
packages/dev-server/package.json

@@ -1,6 +1,6 @@
 {
   "name": "dev-server",
-  "version": "1.2.1",
+  "version": "1.2.2",
   "main": "index.js",
   "license": "MIT",
   "private": true,
@@ -14,18 +14,18 @@
     "load-test:100k": "node -r ts-node/register load-testing/run-load-test.ts 100000"
   },
   "dependencies": {
-    "@vendure/admin-ui-plugin": "^1.2.1",
-    "@vendure/asset-server-plugin": "^1.2.1",
-    "@vendure/common": "^1.2.1",
-    "@vendure/core": "^1.2.1",
-    "@vendure/elasticsearch-plugin": "^1.2.1",
-    "@vendure/email-plugin": "^1.2.1",
+    "@vendure/admin-ui-plugin": "^1.2.2",
+    "@vendure/asset-server-plugin": "^1.2.2",
+    "@vendure/common": "^1.2.2",
+    "@vendure/core": "^1.2.2",
+    "@vendure/elasticsearch-plugin": "^1.2.2",
+    "@vendure/email-plugin": "^1.2.2",
     "typescript": "4.3.5"
   },
   "devDependencies": {
     "@types/csv-stringify": "^3.1.0",
-    "@vendure/testing": "^1.2.1",
-    "@vendure/ui-devkit": "^1.2.1",
+    "@vendure/testing": "^1.2.2",
+    "@vendure/ui-devkit": "^1.2.2",
     "concurrently": "^5.0.0",
     "csv-stringify": "^5.3.3"
   }

+ 3 - 3
packages/elasticsearch-plugin/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@vendure/elasticsearch-plugin",
-  "version": "1.2.1",
+  "version": "1.2.2",
   "license": "MIT",
   "main": "lib/index.js",
   "types": "lib/index.d.ts",
@@ -25,8 +25,8 @@
     "fast-deep-equal": "^3.1.3"
   },
   "devDependencies": {
-    "@vendure/common": "^1.2.1",
-    "@vendure/core": "^1.2.1",
+    "@vendure/common": "^1.2.2",
+    "@vendure/core": "^1.2.2",
     "rimraf": "^3.0.2",
     "typescript": "4.3.5"
   }

+ 3 - 3
packages/email-plugin/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@vendure/email-plugin",
-  "version": "1.2.1",
+  "version": "1.2.2",
   "license": "MIT",
   "main": "lib/index.js",
   "types": "lib/index.d.ts",
@@ -35,8 +35,8 @@
     "@types/fs-extra": "^9.0.1",
     "@types/handlebars": "^4.1.0",
     "@types/mjml": "^4.0.4",
-    "@vendure/common": "^1.2.1",
-    "@vendure/core": "^1.2.1",
+    "@vendure/common": "^1.2.2",
+    "@vendure/core": "^1.2.2",
     "rimraf": "^3.0.2",
     "typescript": "4.3.5"
   }

+ 3 - 3
packages/job-queue-plugin/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@vendure/job-queue-plugin",
-  "version": "1.2.1",
+  "version": "1.2.2",
   "license": "MIT",
   "main": "package/index.js",
   "types": "package/index.d.ts",
@@ -24,8 +24,8 @@
   "devDependencies": {
     "@google-cloud/pubsub": "^2.8.0",
     "@types/redis": "^2.8.28",
-    "@vendure/common": "^1.2.1",
-    "@vendure/core": "^1.2.1",
+    "@vendure/common": "^1.2.2",
+    "@vendure/core": "^1.2.2",
     "bullmq": "^1.40.1",
     "redis": "^3.0.2",
     "rimraf": "^3.0.2",

+ 3 - 3
packages/testing/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@vendure/testing",
-  "version": "1.2.1",
+  "version": "1.2.2",
   "description": "End-to-end testing tools for Vendure projects",
   "keywords": [
     "vendure",
@@ -34,7 +34,7 @@
   },
   "dependencies": {
     "@types/node-fetch": "^2.5.4",
-    "@vendure/common": "^1.2.1",
+    "@vendure/common": "^1.2.2",
     "faker": "^4.1.0",
     "form-data": "^3.0.0",
     "graphql": "15.5.1",
@@ -45,7 +45,7 @@
   "devDependencies": {
     "@types/mysql": "^2.15.15",
     "@types/pg": "^7.14.5",
-    "@vendure/core": "^1.2.1",
+    "@vendure/core": "^1.2.2",
     "mysql": "^2.18.1",
     "pg": "^8.4.0",
     "rimraf": "^3.0.0",

+ 4 - 4
packages/ui-devkit/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@vendure/ui-devkit",
-  "version": "1.2.1",
+  "version": "1.2.2",
   "description": "A library for authoring Vendure Admin UI extensions",
   "keywords": [
     "vendure",
@@ -40,8 +40,8 @@
     "@angular/cli": "12.2.2",
     "@angular/compiler": "12.2.2",
     "@angular/compiler-cli": "12.2.2",
-    "@vendure/admin-ui": "^1.2.1",
-    "@vendure/common": "^1.2.1",
+    "@vendure/admin-ui": "^1.2.2",
+    "@vendure/common": "^1.2.2",
     "chalk": "^4.1.0",
     "chokidar": "^3.5.1",
     "fs-extra": "^10.0.0",
@@ -52,7 +52,7 @@
     "@rollup/plugin-node-resolve": "^11.2.0",
     "@types/fs-extra": "^9.0.8",
     "@types/glob": "^7.1.3",
-    "@vendure/core": "^1.2.1",
+    "@vendure/core": "^1.2.2",
     "rimraf": "^3.0.2",
     "rollup": "^2.40.0",
     "rollup-plugin-terser": "^7.0.2",