Reduce timings

This commit is contained in:
Adria Navarro 2023-09-13 09:37:11 +02:00
parent 0c8a8e1b26
commit 986decb103
1 changed files with 91 additions and 99 deletions

View File

@ -652,9 +652,11 @@ describe.each([
}) })
it("should be able to delete a variety of row set types", async () => { it("should be able to delete a variety of row set types", async () => {
const row1 = await config.createRow() const [row1, row2, row3] = await Promise.all([
const row2 = await config.createRow() config.createRow(),
const row3 = await config.createRow() config.createRow(),
config.createRow(),
])
const rowUsage = await getRowUsage() const rowUsage = await getRowUsage()
const queryUsage = await getQueryUsage() const queryUsage = await getQueryUsage()
@ -1153,12 +1155,11 @@ describe.each([
it("returns empty rows from view when no schema is passed", async () => { it("returns empty rows from view when no schema is passed", async () => {
const table = await config.createTable(await userTable()) const table = await config.createTable(await userTable())
const rows = [] const rows = await Promise.all(
for (let i = 0; i < 10; i++) { Array.from({ length: 10 }, () =>
rows.push( config.api.row.save(table._id!, { tableId: table._id })
await config.api.row.save(table._id!, { tableId: table._id })
) )
} )
const createViewResponse = await config.createView() const createViewResponse = await config.createView()
const response = await config.api.viewV2.search(createViewResponse.id) const response = await config.api.viewV2.search(createViewResponse.id)
@ -1181,22 +1182,26 @@ describe.each([
it("searching respects the view filters", async () => { it("searching respects the view filters", async () => {
const table = await config.createTable(await userTable()) const table = await config.createTable(await userTable())
const expectedRows = []
for (let i = 0; i < 10; i++)
await config.api.row.save(table._id!, {
tableId: table._id,
name: generator.name(),
age: generator.integer({ min: 10, max: 30 }),
})
for (let i = 0; i < 5; i++) await Promise.all(
expectedRows.push( Array.from({ length: 10 }, () =>
await config.api.row.save(table._id!, { config.api.row.save(table._id!, {
tableId: table._id,
name: generator.name(),
age: generator.integer({ min: 10, max: 30 }),
})
)
)
const expectedRows = await Promise.all(
Array.from({ length: 5 }, () =>
config.api.row.save(table._id!, {
tableId: table._id, tableId: table._id,
name: generator.name(), name: generator.name(),
age: 40, age: 40,
}) })
) )
)
const createViewResponse = await config.createView({ const createViewResponse = await config.createView({
query: [{ operator: "equal", field: "age", value: 40 }], query: [{ operator: "equal", field: "age", value: 40 }],
@ -1292,9 +1297,8 @@ describe.each([
], ],
] ]
it.each(sortTestOptions)( describe("sorting", () => {
"allow sorting (%s)", beforeAll(async () => {
async (sortParams, expected) => {
const table = await config.createTable(await userTable()) const table = await config.createTable(await userTable())
const users = [ const users = [
{ name: "Alice", age: 25 }, { name: "Alice", age: 25 },
@ -1302,82 +1306,76 @@ describe.each([
{ name: "Charly", age: 27 }, { name: "Charly", age: 27 },
{ name: "Danny", age: 15 }, { name: "Danny", age: 15 },
] ]
for (const user of users) { await Promise.all(
await config.api.row.save(table._id!, { users.map(u =>
tableId: table._id, config.api.row.save(table._id!, {
...user, tableId: table._id,
...u,
})
)
)
})
it.each(sortTestOptions)(
"allow sorting (%s)",
async (sortParams, expected) => {
const createViewResponse = await config.createView({
sort: sortParams,
schema: viewSchema,
}) })
const response = await config.api.viewV2.search(
createViewResponse.id
)
expect(response.body.rows).toHaveLength(4)
expect(response.body.rows).toEqual(
expected.map(name => expect.objectContaining({ name }))
)
} }
)
const createViewResponse = await config.createView({ it.each(sortTestOptions)(
sort: sortParams, "allow override the default view sorting (%s)",
schema: viewSchema, async (sortParams, expected) => {
}) const createViewResponse = await config.createView({
sort: {
const response = await config.api.viewV2.search(createViewResponse.id) field: "name",
order: SortOrder.ASCENDING,
expect(response.body.rows).toHaveLength(4) type: SortType.STRING,
expect(response.body.rows).toEqual( },
expected.map(name => expect.objectContaining({ name })) schema: viewSchema,
)
}
)
it.each(sortTestOptions)(
"allow override the default view sorting (%s)",
async (sortParams, expected) => {
const table = await config.createTable(await userTable())
const users = [
{ name: "Alice", age: 25 },
{ name: "Bob", age: 30 },
{ name: "Charly", age: 27 },
{ name: "Danny", age: 15 },
]
for (const user of users) {
await config.api.row.save(table._id!, {
tableId: table._id,
...user,
}) })
const response = await config.api.viewV2.search(
createViewResponse.id,
{
sort: sortParams.field,
sortOrder: sortParams.order,
sortType: sortParams.type,
query: {},
}
)
expect(response.body.rows).toHaveLength(4)
expect(response.body.rows).toEqual(
expected.map(name => expect.objectContaining({ name }))
)
} }
)
const createViewResponse = await config.createView({ })
sort: {
field: "name",
order: SortOrder.ASCENDING,
type: SortType.STRING,
},
schema: viewSchema,
})
const response = await config.api.viewV2.search(
createViewResponse.id,
{
sort: sortParams.field,
sortOrder: sortParams.order,
sortType: sortParams.type,
query: {},
}
)
expect(response.body.rows).toHaveLength(4)
expect(response.body.rows).toEqual(
expected.map(name => expect.objectContaining({ name }))
)
}
)
it("when schema is defined, defined columns and row attributes are returned", async () => { it("when schema is defined, defined columns and row attributes are returned", async () => {
const table = await config.createTable(await userTable()) const table = await config.createTable(await userTable())
const rows = [] const rows = await Promise.all(
for (let i = 0; i < 10; i++) { Array.from({ length: 10 }, () =>
rows.push( config.api.row.save(table._id!, {
await config.api.row.save(table._id!, {
tableId: table._id, tableId: table._id,
name: generator.name(), name: generator.name(),
age: generator.age(), age: generator.age(),
}) })
) )
} )
const view = await config.createView({ const view = await config.createView({
schema: { name: { visible: true } }, schema: { name: { visible: true } },
@ -1408,11 +1406,9 @@ describe.each([
}) })
it("respects the limit parameter", async () => { it("respects the limit parameter", async () => {
const table = await config.createTable(await userTable()) await config.createTable(await userTable())
const rows = [] await Promise.all(Array.from({ length: 10 }, () => config.createRow()))
for (let i = 0; i < 10; i++) {
rows.push(await config.createRow())
}
const limit = generator.integer({ min: 1, max: 8 }) const limit = generator.integer({ min: 1, max: 8 })
const createViewResponse = await config.createView() const createViewResponse = await config.createView()
@ -1425,11 +1421,8 @@ describe.each([
}) })
it("can handle pagination", async () => { it("can handle pagination", async () => {
const table = await config.createTable(await userTable()) await config.createTable(await userTable())
const rows = [] await Promise.all(Array.from({ length: 10 }, () => config.createRow()))
for (let i = 0; i < 10; i++) {
rows.push(await config.createRow())
}
const createViewResponse = await config.createView() const createViewResponse = await config.createView()
const allRows = (await config.api.viewV2.search(createViewResponse.id)) const allRows = (await config.api.viewV2.search(createViewResponse.id))
@ -1489,11 +1482,10 @@ describe.each([
let tableId: string let tableId: string
beforeAll(async () => { beforeAll(async () => {
const table = await config.createTable(await userTable()) await config.createTable(await userTable())
const rows = [] await Promise.all(
for (let i = 0; i < 10; i++) { Array.from({ length: 10 }, () => config.createRow())
rows.push(await config.createRow()) )
}
const createViewResponse = await config.createView() const createViewResponse = await config.createView()