Skip to content

Commit

Permalink
docs: added an upgrade guide for v1.10.0 (medusajs#4013)
Browse files Browse the repository at this point in the history
* docs: added an upgrade guide for v1.10.0

* removed redis update command

* small text fix

* Update 1-10-0.md

---------

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
  • Loading branch information
shahednasser and olivermrbl authored May 4, 2023
1 parent 731f05d commit 98f7055
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 31 deletions.
31 changes: 0 additions & 31 deletions docs/content/development/events/create-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,37 +192,6 @@ class CustomEventBus extends AbstractEventBusModuleService {
}
```

### (optional) retrieveSubscribers

This method is also implemented in the `AbstractEventBusModuleService` class. This section explains how you can override it to implement your custom logic, if necessary.

The `retrieveSubscribers` method is used to retrieve the subscribers to a specific event. If there are no subscribers to an event, the event is not stored in the database or processed by the event bus module.

The `retrieveSubscribers` method accepts one parameter, which is the name of the event. It should return an array of objects of the following type:

```ts
type SubscriberDescriptor = {
id: string
subscriber: Subscriber
}
```
Where:
- `id` is a string that is the ID of a subscriber.
- `subscriber` is a subscriber class.
For example, here's how the `retrieveSubscribers` is implemented in the `AbstractEventBusModuleService`:
```ts title=services/event-bus-custom.ts
class CustomEventBus extends AbstractEventBusModuleService {
// ...
retrieveSubscribers(event: string | symbol) {
return this.eventToSubscribersMap_.get(event)
}
}
```

---

## Step 3: Export the Service
Expand Down
57 changes: 57 additions & 0 deletions docs/content/upgrade-guides/medusa-core/1-10-0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
description: 'Actions Required for v.1.10.0'
sidebar_custom_props:
iconName: 'server-stack-solid'
---

# v1.10.0

Version 1.10.0 of Medusa introduces performance improvement related to Typeorm and the removal of the `retrieveSubscribers` previously added to the event bus service.

## Overview

### Typeorm Performance Improvement

To improve performance of Cart and Product retrieval, our team has changed the `relationLoadStrategy` in Typeorm from join to query. This means relations are loaded using separate database queries rather than many joins in a single large query. This change also significantly reduces memory usage, as it will produce a much smaller result set to store in memory.

Unfortunately, Typeorm's query-strategy does not work well in concert with transactions, which is extensively used across our codebase. The separate queries to fetch relations on entities will run outside of an initiated transaction, because it uses a different query runner. This leads to incorrect results in cases where you request entities previously created in an ongoing transaction. Those changes will not have persisted to the database at the time of querying, and will therefore be "invisible" to other query runners.

Instead of compromising on the performance of our API, our team decided to fix the issue in Typeorm, which can be found in [this PR](https://github.com/typeorm/typeorm/pull/9990) on Typeorm's repository. It is still yet to be merged, so, for now, our team has published a forked version of Typeorm that includes the fix. This is the breaking change of this release.

### retrieveSubscribers Removal

The `retrieveSubscribers` was introduced in a previous version to ensure that events are triggered only if a subscriber was listening to that event. However, the approach implemented caused unanticipated issues with the triggering of events.

So, this method has been removed from the event bus service. If you've implemented this event in your custom event bus service, this should cause no issues, but your `retrieveSubscribers` method will not be used anymore.

---

## How to Update

Run the following command in the root directory of your Medusa Backend to update the core:

```bash npm2yarn
npm install @medusajs/medusa@1.10.0
```

If you are using our local event bus, run the following command to update the event system:

```bash npm2yarn
npm install @medusajs/event-bus-local@1.9.1
```

It's also recommended to update any other Medusa plugins or packages you have installed.

---

## Actions Required

### Change Typeorm Package

To make sure your project works as expected, you'll need to use our forked Typeorm version in your project until Typeorm merges our PR and publishes a new version.

In your `package.json`, replace the Typeorm version with the following:

```json
"typeorm": "npm:@medusajs/typeorm@next"
```

0 comments on commit 98f7055

Please sign in to comment.