Skip to content

Commit

Permalink
fix(core): Default search plugin query for non-default language fails
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-rollingridges-dev committed Nov 19, 2023
1 parent 72cdabf commit d5f781c
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ export const fieldsToSelect = [
'productVariantPreviewFocalPoint',
];

export const identifierFields = [
'channelId',
'productVariantId',
'productId',
'productAssetId',
'productVariantAssetId',
];

export function getFieldsToSelect(includeStockStatus: boolean = false) {
return includeStockStatus ? [...fieldsToSelect, 'inStock', 'productInStock'] : fieldsToSelect;
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,24 @@ export function applyLanguageConstraints(
languageCode,
});
} else {
const count = qb
.subQuery()
.select('COUNT(*) as countLanguageCode')
.from(SearchIndexItem, 'sil')
.where(`sil.${ciEscaped} = si.${ciEscaped}`)
.andWhere(`sil.${pviEscaped} = si.${pviEscaped}`)
.andWhere(`sil.${lcEscaped} = :countLanguageCode`)
.getQuery();
qb.andWhere(`si.${lcEscaped} IN (:...languageCodes)`, {
languageCodes: [languageCode, defaultLanguageCode],
});

qb.leftJoin(
SearchIndexItem,
'sil',
`sil.${lcEscaped} = :languageCode AND sil.${ciEscaped} = si.${ciEscaped} AND sil.${pviEscaped} = si.${pviEscaped}`,
{
languageCode,
},
);

qb.andWhere(
new Brackets(qb1 => {
qb1.where(`si.${lcEscaped} = :languageCode`, {
languageCode,
}).orWhere(
new Brackets(qb2 => {
qb2.where(`si.${lcEscaped} = :defaultLanguageCode`, {
defaultLanguageCode,
}).andWhere(`NOT(1 IN (${count}))`, {
countLanguageCode: languageCode,
});
}),
);
qb1.where(`si.${lcEscaped} = :languageCode1`, {
languageCode1: languageCode,
}).orWhere(`sil.${lcEscaped} IS NULL`);
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mutation SetShippingMethod($id: ID!) {
mutation SetShippingMethod($id: [ID!]!) {
setOrderShippingMethod(shippingMethodId: $id) {
...on Order {
code
Expand Down
16 changes: 15 additions & 1 deletion packages/dev-server/load-testing/init-load-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// <reference path="../../core/typings.d.ts" />
import { bootstrap, JobQueueService, Logger } from '@vendure/core';
import { populate } from '@vendure/core/cli/populate';
import { clearAllTables, populateCustomers } from '@vendure/testing';
import { clearAllTables, populateCustomers, SimpleGraphQLClient } from '@vendure/testing';
import stringify from 'csv-stringify';
import fs from 'fs';
import path from 'path';
Expand All @@ -17,6 +17,8 @@ import {
getProductCsvFilePath,
} from './load-test-config';

import { awaitRunningJobs } from '../../core/e2e/utils/await-running-jobs';

/* eslint-disable no-console */

/**
Expand Down Expand Up @@ -49,6 +51,18 @@ if (require.main === module) {
csvFile,
),
)
.then(async app => {
console.log('synchronize on search index updated...');
const { port, adminApiPath, shopApiPath } = config.apiOptions;
const adminClient = new SimpleGraphQLClient(
config,
`http://localhost:${port}/${adminApiPath!}`,
);
await adminClient.asSuperAdmin();
await new Promise(resolve => setTimeout(resolve, 5000));
await awaitRunningJobs(adminClient, 5000000);
return app;
})
.then(async app => {
console.log('populating customers...');
await populateCustomers(app, 10, message => Logger.error(message));
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-server/load-testing/load-test-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function getLoadTestConfig(
assetUploadDir: path.join(__dirname, 'static/assets'),
route: 'assets',
}),
DefaultSearchPlugin,
DefaultSearchPlugin.init({ bufferUpdates: false, indexStockStatus: false }),
DefaultJobQueuePlugin.init({
pollInterval: 1000,
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/dev-server/load-testing/run-load-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if (require.main === module) {
stdio: 'inherit',
});

init.on('exit', code => {
init.on('exit', async code => {
if (code === 0) {
const databaseName = `vendure-load-testing-${count}`;
return bootstrap(getLoadTestConfig('cookie', databaseName))
Expand All @@ -49,7 +49,7 @@ if (require.main === module) {
});
}

function runLoadTestScript(script: string): Promise<LoadTestSummary> {
async function runLoadTestScript(script: string): Promise<LoadTestSummary> {
const rawResultsFile = `${script}.${count}.json`;

return new Promise((resolve, reject) => {
Expand Down
10 changes: 6 additions & 4 deletions packages/dev-server/load-testing/scripts/search-and-checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ export default function () {
addToCart(randomItem(product.variants).id);
}
setShippingAddressAndCustomer();
const data = getShippingMethodsQuery.post().data;
const result = completeOrderMutation.post({ id: data.eligibleShippingMethods[0].id }).data;
check(result, {
'Order completed': r => r.addPaymentToOrder.state === 'PaymentAuthorized',
const { data: shippingMethods } = getShippingMethodsQuery.post();
const { data: order } = completeOrderMutation.post({
id: [shippingMethods.eligibleShippingMethods.at(0).id],
});
check(order, {
'Order completed': o => o.addPaymentToOrder.state === 'PaymentAuthorized',
});
}

Expand Down
11 changes: 7 additions & 4 deletions packages/dev-server/load-testing/utils/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ export class ApiRequest {
post(variables = {}, authToken) {
const res = http.post(
this.apiUrl,
{
JSON.stringify({
query: this.document,
variables: JSON.stringify(variables),
},
variables,
}),
{
timeout: 120 * 1000,
headers: { Authorization: authToken ? `Bearer ${authToken}` : undefined },
headers: {
Authorization: authToken ? `Bearer ${authToken}` : '',
'Content-Type': 'application/json',
},
},
);
check(res, {
Expand Down

0 comments on commit d5f781c

Please sign in to comment.