-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Channel cache can handle more than 1000 channels
Fixes #2233
- Loading branch information
1 parent
adca2dd
commit 2218d42
Showing
4 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* eslint-disable no-console */ | ||
import { | ||
bootstrapWorker, | ||
ChannelService, | ||
CurrencyCode, | ||
isGraphQlErrorResult, | ||
LanguageCode, | ||
RequestContextService, | ||
RoleService, | ||
} from '@vendure/core'; | ||
|
||
import { devConfig } from '../dev-config'; | ||
|
||
const CHANNEL_COUNT = 1001; | ||
|
||
generateManyChannels() | ||
.then(() => process.exit(0)) | ||
.catch(() => process.exit(1)); | ||
|
||
// Used for testing scenarios where there are many channels | ||
// such as https://github.com/vendure-ecommerce/vendure/issues/2233 | ||
async function generateManyChannels() { | ||
const { app } = await bootstrapWorker(devConfig); | ||
const requestContextService = app.get(RequestContextService); | ||
const channelService = app.get(ChannelService); | ||
const roleService = app.get(RoleService); | ||
|
||
const ctxAdmin = await requestContextService.create({ | ||
apiType: 'admin', | ||
}); | ||
|
||
const superAdminRole = await roleService.getSuperAdminRole(ctxAdmin); | ||
const customerRole = await roleService.getCustomerRole(ctxAdmin); | ||
|
||
for (let i = CHANNEL_COUNT; i > 0; i--) { | ||
const channel = await channelService.create(ctxAdmin, { | ||
code: `channel-test-${i}`, | ||
token: `channel--test-${i}`, | ||
defaultLanguageCode: LanguageCode.en, | ||
availableLanguageCodes: [LanguageCode.en], | ||
pricesIncludeTax: true, | ||
defaultCurrencyCode: CurrencyCode.USD, | ||
availableCurrencyCodes: [CurrencyCode.USD], | ||
sellerId: 1, | ||
defaultTaxZoneId: 1, | ||
defaultShippingZoneId: 1, | ||
}); | ||
if (isGraphQlErrorResult(channel)) { | ||
console.log(channel.message); | ||
} else { | ||
console.log(`Created channel ${channel.code}`); | ||
await roleService.assignRoleToChannel(ctxAdmin, superAdminRole.id, channel.id); | ||
await roleService.assignRoleToChannel(ctxAdmin, customerRole.id, channel.id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters