* feat: optimize collection list relationship queries (#749)
* feat: optimize collection list relationship queries
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
/* eslint-disable no-console */
|
||||
import express from 'express';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import payload from '../../src';
|
||||
|
||||
const expressApp = express();
|
||||
|
||||
const init = async () => {
|
||||
await payload.init({
|
||||
secret: 'SECRET_KEY',
|
||||
secret: uuid(),
|
||||
mongoURL: process.env.MONGO_URL || 'mongodb://localhost/payload',
|
||||
express: expressApp,
|
||||
email: {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { CollectionConfig } from '../../../src/collections/config/types';
|
||||
import { buildConfig } from '../buildConfig';
|
||||
import { devUser } from '../../credentials';
|
||||
|
||||
export const slug = 'fields-relationship';
|
||||
|
||||
@@ -38,6 +39,9 @@ export default buildConfig({
|
||||
collections: [
|
||||
{
|
||||
slug,
|
||||
admin: {
|
||||
defaultColumns: ['relationship', 'relationshipRestricted', 'with-existing-relations'],
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
type: 'relationship',
|
||||
@@ -94,6 +98,13 @@ export default buildConfig({
|
||||
},
|
||||
],
|
||||
onInit: async (payload) => {
|
||||
await payload.create({
|
||||
collection: 'users',
|
||||
data: {
|
||||
email: devUser.email,
|
||||
password: devUser.password,
|
||||
},
|
||||
});
|
||||
// Create docs to relate to
|
||||
const { id: relationOneDocId } = await payload.create<RelationOne>({
|
||||
collection: relationOneSlug,
|
||||
@@ -129,10 +140,9 @@ export default buildConfig({
|
||||
name: 'relation-title',
|
||||
},
|
||||
});
|
||||
await payload.create<RelationOne>({
|
||||
await payload.create<FieldsRelationship>({
|
||||
collection: slug,
|
||||
data: {
|
||||
name: 'with-existing-relations',
|
||||
relationship: relationOneDocId,
|
||||
relationshipRestricted: restrictedDocId,
|
||||
relationshipWithTitle: relationWithTitleDocId,
|
||||
|
||||
@@ -4,7 +4,7 @@ import payload from '../../../src';
|
||||
import { mapAsync } from '../../../src/utilities/mapAsync';
|
||||
import { AdminUrlUtil } from '../../helpers/adminUrlUtil';
|
||||
import { initPayloadTest } from '../../helpers/configHelpers';
|
||||
import { firstRegister, saveDocAndAssert } from '../helpers';
|
||||
import { login, saveDocAndAssert } from '../helpers';
|
||||
import type {
|
||||
FieldsRelationship as CollectionWithRelationships,
|
||||
RelationOne,
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
relationWithTitleSlug,
|
||||
slug,
|
||||
} from './config';
|
||||
import wait from '../../../src/utilities/wait';
|
||||
|
||||
const { beforeAll, describe } = test;
|
||||
|
||||
@@ -97,7 +98,7 @@ describe('fields - relationship', () => {
|
||||
},
|
||||
});
|
||||
|
||||
await firstRegister({ page, serverURL });
|
||||
await login({ page, serverURL });
|
||||
});
|
||||
|
||||
test('should create relationship', async () => {
|
||||
@@ -216,6 +217,30 @@ describe('fields - relationship', () => {
|
||||
|
||||
await expect(options).toHaveCount(2); // None + 1 Doc
|
||||
});
|
||||
|
||||
test('should show id on relation in list view', async () => {
|
||||
await page.goto(url.list);
|
||||
await wait(1000);
|
||||
const cells = page.locator('.relationship');
|
||||
const relationship = cells.nth(0);
|
||||
await expect(relationship).toHaveText(relationOneDoc.id);
|
||||
});
|
||||
|
||||
test('should show useAsTitle on relation in list view', async () => {
|
||||
await page.goto(url.list);
|
||||
wait(110);
|
||||
const cells = page.locator('.relationshipWithTitle');
|
||||
const relationship = cells.nth(0);
|
||||
await expect(relationship).toHaveText(relationWithTitle.id);
|
||||
});
|
||||
|
||||
test('should show untitled ID on restricted relation in list view', async () => {
|
||||
await page.goto(url.list);
|
||||
wait(110);
|
||||
const cells = page.locator('.relationship');
|
||||
const relationship = cells.nth(0);
|
||||
await expect(relationship).toHaveText(relationOneDoc.id);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user