diff --git a/packages/plugin-search/src/utilities/generateReindexHandler.ts b/packages/plugin-search/src/utilities/generateReindexHandler.ts index 5ec0700f7..c10ad0caa 100644 --- a/packages/plugin-search/src/utilities/generateReindexHandler.ts +++ b/packages/plugin-search/src/utilities/generateReindexHandler.ts @@ -149,17 +149,23 @@ export const generateReindexHandler = await initTransaction(req) - for (const collection of collections) { - try { - await deleteIndexes(collection) - await reindexCollection(collection) - } catch (err) { - const message = t('error:unableToReindexCollection', { collection }) - payload.logger.error({ err, msg: message }) + try { + const promises = collections.map(async (collection) => { + try { + await deleteIndexes(collection) + await reindexCollection(collection) + } catch (err) { + const message = t('error:unableToReindexCollection', { collection }) + payload.logger.error({ err, msg: message }) - await killTransaction(req) - return Response.json({ message }, { headers, status: 500 }) - } + await killTransaction(req) + throw new Error(message) + } + }) + + await Promise.all(promises) + } catch (err: any) { + return Response.json({ message: err.message }, { headers, status: 500 }) } const message = t('general:successfullyReindexed', { diff --git a/test/plugin-search/int.spec.ts b/test/plugin-search/int.spec.ts index 1271d46f2..80e2a6e5b 100644 --- a/test/plugin-search/int.spec.ts +++ b/test/plugin-search/int.spec.ts @@ -494,20 +494,22 @@ describe('@payloadcms/plugin-search', () => { }) it('should reindex whole collections', async () => { - await payload.create({ - collection: pagesSlug, - data: { - title: 'Test page title', - _status: 'published', - }, - }) - await payload.create({ - collection: postsSlug, - data: { - title: 'Test page title', - _status: 'published', - }, - }) + await Promise.all([ + payload.create({ + collection: pagesSlug, + data: { + title: 'Test page title', + _status: 'published', + }, + }), + payload.create({ + collection: postsSlug, + data: { + title: 'Test page title', + _status: 'published', + }, + }), + ]) await wait(200) diff --git a/test/plugin-search/payload-types.ts b/test/plugin-search/payload-types.ts index 595bad643..7478e3766 100644 --- a/test/plugin-search/payload-types.ts +++ b/test/plugin-search/payload-types.ts @@ -136,6 +136,13 @@ export interface User { hash?: string | null; loginAttempts?: number | null; lockUntil?: string | null; + sessions?: + | { + id: string; + createdAt?: string | null; + expiresAt: string; + }[] + | null; password?: string | null; } /** @@ -300,6 +307,13 @@ export interface UsersSelect { hash?: T; loginAttempts?: T; lockUntil?: T; + sessions?: + | T + | { + id?: T; + createdAt?: T; + expiresAt?: T; + }; } /** * This interface was referenced by `Config`'s JSON-Schema