Skip to content

Commit

Permalink
Merge branch 'master' into minor
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Feb 14, 2025
2 parents 0bef00b + 338a61e commit 65ad028
Show file tree
Hide file tree
Showing 34 changed files with 405 additions and 218 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## <small>3.1.3 (2025-02-14)</small>


#### Fixes

* **admin-ui** Improve display of OrderLine custom fields in form ([4e92d85](https://github.com/vendure-ecommerce/vendure/commit/4e92d85))
* **core** Allow non-public customOrderLineFields in admin api (#3357) ([becfe9d](https://github.com/vendure-ecommerce/vendure/commit/becfe9d)), closes [#3357](https://github.com/vendure-ecommerce/vendure/issues/3357)
* **core** Fix undefined type issue with nested fragment spreads (#3351) ([d0c0454](https://github.com/vendure-ecommerce/vendure/commit/d0c0454)), closes [#3351](https://github.com/vendure-ecommerce/vendure/issues/3351)

#### Perf

* **core** Optimize payload of apply-collection-filters job ([4157033](https://github.com/vendure-ecommerce/vendure/commit/4157033))
* **core** Optimize payload size for buffered jobs in DB ([f81a908](https://github.com/vendure-ecommerce/vendure/commit/f81a908))
* **job-queue-plugin** Optimize payload size for buffered jobs in Redis ([7c72352](https://github.com/vendure-ecommerce/vendure/commit/7c72352))

## <small>3.1.2 (2025-01-22)</small>


Expand Down
4 changes: 2 additions & 2 deletions docs/docs/guides/developer-guide/plugins/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ By convention, we'll store the entity definitions in the `entities` directory of

```ts title="src/plugins/wishlist-plugin/entities/wishlist-item.entity.ts"
import { DeepPartial, ID, ProductVariant, VendureEntity, EntityId } from '@vendure/core';
import { Column, Entity, ManyToOne } from 'typeorm';
import { Entity, ManyToOne } from 'typeorm';

@Entity()
export class WishlistItem extends VendureEntity {
Expand Down Expand Up @@ -727,7 +727,7 @@ We can then query the wishlist items:


<Tabs>
<TabItem value="GetWishlist mutation" label="GetWishlist mutation" default>
<TabItem value="GetWishlist query" label="GetWishlist query" default>

```graphql
query GetWishlist {
Expand Down
55 changes: 54 additions & 1 deletion docs/docs/guides/developer-guide/worker-job-queue/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class ProductVideoPlugin {}

### Passing the RequestContext

It is common to need to pass the [RequestContext object](/reference/typescript-api/request/request-context) to the `process` function of a job, since `ctx` is required by many Vendure
Sometimes you need to pass the [RequestContext object](/reference/typescript-api/request/request-context) to the `process` function of a job, since `ctx` is required by many Vendure
service methods that you may be using inside your `process` function. However, the `RequestContext` object itself is not serializable,
so it cannot be passed directly to the `JobQueue.add()` method. Instead, you can serialize the `RequestContext` using the [`RequestContext.serialize()`
method](/reference/typescript-api/request/request-context/#serialize), and then deserialize it in the `process` function using the static `deserialize` method:
Expand Down Expand Up @@ -363,6 +363,59 @@ class ProductExportService implements OnModuleInit {
}
```

:::warning
Serializing the RequestContext should be done with caution, since it is a relatively large object and will significantly increase the size of the job data.

In cases where the job is created in large quantities (hundreds or thousands of jobs per day), this can lead to performance issues. Especially
when using the [BullMQJobQueuePlugin](/reference/core-plugins/job-queue-plugin/bull-mqjob-queue-plugin/), which stores the job data in Redis, the
size of the job data can lead to too much memory usage which can cause the Redis server to crash.
:::

Instead of serializing the entire RequestContext, consider passing only the necessary data you need and then reconstructing the RequestContext in the `process` function:

```ts
import { Injectable, OnModuleInit } from '@nestjs/common';
import { JobQueue, JobQueueService,
RequestContext, ID, LanguageCode, RequestContextService } from '@vendure/core';

@Injectable()
class ProductExportService implements OnModuleInit {

// highlight-next-line
private jobQueue: JobQueue<{ channelToken: string; languageCode: LanguageCode; }>;

constructor(private jobQueueService: JobQueueService,
private requestContextService: RequestContextService) {
}

async onModuleInit() {
this.jobQueue = await this.jobQueueService.createQueue({
name: 'export-products',
process: async job => {
// highlight-start
// Reconstruct the RequestContext from the passed data
const ctx = await this.requestContextService.create({
channelOrToken: job.data.channelToken,
languageCode: job.data.languageCode,
})
// highlight-end
// ... logic to export the product omitted for brevity
},
});
}

exportAllProducts(ctx: RequestContext) {
// highlight-start
// Pass only the necessary data
return this.jobQueue.add({
channelId: ctx.channel.token,
languageCode: ctx.languageCode
});
// highlight-end
}
}
```

### Handling job cancellation

It is possible for an administrator to cancel a running job. Doing so will cause the configured job queue strategy to mark the job as cancelled, but
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packages": ["packages/*"],
"version": "3.1.2",
"version": "3.1.3",
"npmClient": "npm",
"command": {
"version": {
Expand Down
24 changes: 24 additions & 0 deletions license/signatures/version1/cla.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,30 @@
"created_at": "2025-02-07T12:21:59Z",
"repoId": 136938012,
"pullRequestNo": 3351
},
{
"name": "kamui",
"id": 2255,
"comment_id": 2649402776,
"created_at": "2025-02-10T22:30:15Z",
"repoId": 136938012,
"pullRequestNo": 3359
},
{
"name": "hooooooouzx",
"id": 50389824,
"comment_id": 2656943842,
"created_at": "2025-02-13T15:22:59Z",
"repoId": 136938012,
"pullRequestNo": 3363
},
{
"name": "Ryrahul",
"id": 121729670,
"comment_id": 2657081786,
"created_at": "2025-02-13T16:09:46Z",
"repoId": 136938012,
"pullRequestNo": 3365
}
]
}
Loading

0 comments on commit 65ad028

Please sign in to comment.