Merge branch 'master' into feature/multistep-form-block

This commit is contained in:
deanhannigan 2024-01-05 09:27:46 +00:00 committed by GitHub
commit 0022034719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 81 additions and 882 deletions

View File

@ -109,7 +109,7 @@ services:
redis-service: redis-service:
restart: unless-stopped restart: unless-stopped
image: redis image: redis
command: redis-server --requirepass ${REDIS_PASSWORD} command: redis-server --requirepass "${REDIS_PASSWORD}"
volumes: volumes:
- redis_data:/data - redis_data:/data

View File

@ -2,7 +2,6 @@ import Redlock from "redlock"
import { getLockClient } from "./init" import { getLockClient } from "./init"
import { LockOptions, LockType } from "@budibase/types" import { LockOptions, LockType } from "@budibase/types"
import * as context from "../context" import * as context from "../context"
import { logWarn } from "../logging"
import { utils } from "@budibase/shared-core" import { utils } from "@budibase/shared-core"
import { Duration } from "../utils" import { Duration } from "../utils"

@ -1 +1 @@
Subproject commit dc2b1b22e7f9bac705746bf1fb72c817db043fa3 Subproject commit b1c10c2daf808d103724c324256cbff67f33fb46

View File

@ -161,11 +161,8 @@ export async function preview(ctx: UserCtx) {
auth: { ...authConfigCtx }, auth: { ...authConfigCtx },
}, },
} }
const runFn = () => Runner.run(inputs)
const { rows, keys, info, extra } = await quotas.addQuery<any>(runFn, { const { rows, keys, info, extra } = (await Runner.run(inputs)) as any
datasourceId: datasource._id,
})
const schemaFields: any = {} const schemaFields: any = {}
if (rows?.length > 0) { if (rows?.length > 0) {
for (let key of [...new Set(keys)] as string[]) { for (let key of [...new Set(keys)] as string[]) {
@ -259,14 +256,8 @@ async function execute(
}, },
schema: query.schema, schema: query.schema,
} }
const runFn = () => Runner.run(inputs)
const { rows, pagination, extra, info } = await quotas.addQuery<any>( const { rows, pagination, extra, info } = (await Runner.run(inputs)) as any
runFn,
{
datasourceId: datasource._id,
}
)
// remove the raw from execution incase transformer being used to hide data // remove the raw from execution incase transformer being used to hide data
if (extra?.raw) { if (extra?.raw) {
delete extra.raw delete extra.raw

View File

@ -4,20 +4,20 @@ import * as external from "./external"
import { isExternalTableID } from "../../../integrations/utils" import { isExternalTableID } from "../../../integrations/utils"
import { import {
Ctx, Ctx,
UserCtx,
DeleteRowRequest,
DeleteRow, DeleteRow,
DeleteRowRequest,
DeleteRows, DeleteRows,
Row,
PatchRowRequest,
PatchRowResponse,
SearchRowResponse,
SearchRowRequest,
SearchParams,
GetRowResponse,
ValidateResponse,
ExportRowsRequest, ExportRowsRequest,
ExportRowsResponse, ExportRowsResponse,
GetRowResponse,
PatchRowRequest,
PatchRowResponse,
Row,
SearchParams,
SearchRowRequest,
SearchRowResponse,
UserCtx,
ValidateResponse,
} from "@budibase/types" } from "@budibase/types"
import * as utils from "./utils" import * as utils from "./utils"
import { gridSocket } from "../../../websockets" import { gridSocket } from "../../../websockets"
@ -25,8 +25,8 @@ import { addRev } from "../public/utils"
import { fixRow } from "../public/rows" import { fixRow } from "../public/rows"
import sdk from "../../../sdk" import sdk from "../../../sdk"
import * as exporters from "../view/exporters" import * as exporters from "../view/exporters"
import { apiFileReturn } from "../../../utilities/fileSystem"
import { Format } from "../view/exporters" import { Format } from "../view/exporters"
import { apiFileReturn } from "../../../utilities/fileSystem"
export * as views from "./views" export * as views from "./views"
@ -49,12 +49,7 @@ export async function patch(
return save(ctx) return save(ctx)
} }
try { try {
const { row, table } = await quotas.addQuery( const { row, table } = await pickApi(tableId).patch(ctx)
() => pickApi(tableId).patch(ctx),
{
datasourceId: tableId,
}
)
if (!row) { if (!row) {
ctx.throw(404, "Row not found") ctx.throw(404, "Row not found")
} }
@ -84,12 +79,7 @@ export const save = async (ctx: UserCtx<Row, Row>) => {
return patch(ctx as UserCtx<PatchRowRequest, PatchRowResponse>) return patch(ctx as UserCtx<PatchRowRequest, PatchRowResponse>)
} }
const { row, table, squashed } = await quotas.addRow(() => const { row, table, squashed } = await quotas.addRow(() =>
quotas.addQuery( sdk.rows.save(tableId, ctx.request.body, ctx.user?._id)
() => sdk.rows.save(tableId, ctx.request.body, ctx.user?._id),
{
datasourceId: tableId,
}
)
) )
ctx.status = 200 ctx.status = 200
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table) ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table)
@ -105,31 +95,21 @@ export async function fetchView(ctx: any) {
const { calculation, group, field } = ctx.query const { calculation, group, field } = ctx.query
ctx.body = await quotas.addQuery( ctx.body = await sdk.rows.fetchView(tableId, viewName, {
() =>
sdk.rows.fetchView(tableId, viewName, {
calculation, calculation,
group: calculation ? group : null, group: calculation ? group : null,
field, field,
}), })
{
datasourceId: tableId,
}
)
} }
export async function fetch(ctx: any) { export async function fetch(ctx: any) {
const tableId = utils.getTableId(ctx) const tableId = utils.getTableId(ctx)
ctx.body = await quotas.addQuery(() => sdk.rows.fetch(tableId), { ctx.body = await sdk.rows.fetch(tableId)
datasourceId: tableId,
})
} }
export async function find(ctx: UserCtx<void, GetRowResponse>) { export async function find(ctx: UserCtx<void, GetRowResponse>) {
const tableId = utils.getTableId(ctx) const tableId = utils.getTableId(ctx)
ctx.body = await quotas.addQuery(() => pickApi(tableId).find(ctx), { ctx.body = await pickApi(tableId).find(ctx)
datasourceId: tableId,
})
} }
function isDeleteRows(input: any): input is DeleteRows { function isDeleteRows(input: any): input is DeleteRows {
@ -160,15 +140,9 @@ async function deleteRows(ctx: UserCtx<DeleteRowRequest>) {
let deleteRequest = ctx.request.body as DeleteRows let deleteRequest = ctx.request.body as DeleteRows
const rowDeletes: Row[] = await processDeleteRowsRequest(ctx) deleteRequest.rows = await processDeleteRowsRequest(ctx)
deleteRequest.rows = rowDeletes
const { rows } = await quotas.addQuery( const { rows } = await pickApi(tableId).bulkDestroy(ctx)
() => pickApi(tableId).bulkDestroy(ctx),
{
datasourceId: tableId,
}
)
await quotas.removeRows(rows.length) await quotas.removeRows(rows.length)
for (let row of rows) { for (let row of rows) {
@ -183,9 +157,7 @@ async function deleteRow(ctx: UserCtx<DeleteRowRequest>) {
const appId = ctx.appId const appId = ctx.appId
const tableId = utils.getTableId(ctx) const tableId = utils.getTableId(ctx)
const resp = await quotas.addQuery(() => pickApi(tableId).destroy(ctx), { const resp = await pickApi(tableId).destroy(ctx)
datasourceId: tableId,
})
await quotas.removeRow() await quotas.removeRow()
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, resp.row) ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, resp.row)
@ -223,9 +195,7 @@ export async function search(ctx: Ctx<SearchRowRequest, SearchRowResponse>) {
} }
ctx.status = 200 ctx.status = 200
ctx.body = await quotas.addQuery(() => sdk.rows.search(searchParams), { ctx.body = await sdk.rows.search(searchParams)
datasourceId: tableId,
})
} }
export async function validate(ctx: Ctx<Row, ValidateResponse>) { export async function validate(ctx: Ctx<Row, ValidateResponse>) {
@ -243,12 +213,7 @@ export async function validate(ctx: Ctx<Row, ValidateResponse>) {
export async function fetchEnrichedRow(ctx: any) { export async function fetchEnrichedRow(ctx: any) {
const tableId = utils.getTableId(ctx) const tableId = utils.getTableId(ctx)
ctx.body = await quotas.addQuery( ctx.body = await pickApi(tableId).fetchEnrichedRow(ctx)
() => pickApi(tableId).fetchEnrichedRow(ctx),
{
datasourceId: tableId,
}
)
} }
export const exportRows = async ( export const exportRows = async (
@ -268,8 +233,6 @@ export const exportRows = async (
) )
} }
ctx.body = await quotas.addQuery(
async () => {
const { fileName, content } = await sdk.rows.exportRows({ const { fileName, content } = await sdk.rows.exportRows({
tableId, tableId,
format: format as Format, format: format as Format,
@ -280,10 +243,5 @@ export const exportRows = async (
sortOrder, sortOrder,
}) })
ctx.attachment(fileName) ctx.attachment(fileName)
return apiFileReturn(content) ctx.body = apiFileReturn(content)
},
{
datasourceId: tableId,
}
)
} }

View File

@ -68,10 +68,7 @@ export async function searchView(
paginate: body.paginate, paginate: body.paginate,
} }
const result = await quotas.addQuery(() => sdk.rows.search(searchOptions), { const result = await sdk.rows.search(searchOptions)
datasourceId: view.tableId,
})
result.rows.forEach(r => (r._viewId = view.id)) result.rows.forEach(r => (r._viewId = view.id))
ctx.body = result ctx.body = result
} }

View File

@ -132,11 +132,6 @@ describe.each([
expect(usage).toBe(expected) expect(usage).toBe(expected)
} }
const assertQueryUsage = async (expected: number) => {
const usage = await getQueryUsage()
expect(usage).toBe(expected)
}
const defaultRowFields = isInternal const defaultRowFields = isInternal
? { ? {
type: "row", type: "row",
@ -181,7 +176,6 @@ describe.each([
expect(res.body.name).toEqual("Test Contact") expect(res.body.name).toEqual("Test Contact")
expect(res.body._rev).toBeDefined() expect(res.body._rev).toBeDefined()
await assertRowUsage(rowUsage + 1) await assertRowUsage(rowUsage + 1)
await assertQueryUsage(queryUsage + 1)
}) })
it("Increment row autoId per create row request", async () => { it("Increment row autoId per create row request", async () => {
@ -232,7 +226,6 @@ describe.each([
} }
await assertRowUsage(rowUsage + ids.length) await assertRowUsage(rowUsage + ids.length)
await assertQueryUsage(queryUsage + ids.length)
}) })
it("updates a row successfully", async () => { it("updates a row successfully", async () => {
@ -249,7 +242,6 @@ describe.each([
expect(res.name).toEqual("Updated Name") expect(res.name).toEqual("Updated Name")
await assertRowUsage(rowUsage) await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage + 1)
}) })
it("should load a row", async () => { it("should load a row", async () => {
@ -262,7 +254,6 @@ describe.each([
...existing, ...existing,
...defaultRowFields, ...defaultRowFields,
}) })
await assertQueryUsage(queryUsage + 1)
}) })
it("should list all rows for given tableId", async () => { it("should list all rows for given tableId", async () => {
@ -284,7 +275,6 @@ describe.each([
expect(res.length).toBe(2) expect(res.length).toBe(2)
expect(res.find((r: Row) => r.name === newRow.name)).toBeDefined() expect(res.find((r: Row) => r.name === newRow.name)).toBeDefined()
expect(res.find((r: Row) => r.name === firstRow.name)).toBeDefined() expect(res.find((r: Row) => r.name === firstRow.name)).toBeDefined()
await assertQueryUsage(queryUsage + 1)
}) })
it("load should return 404 when row does not exist", async () => { it("load should return 404 when row does not exist", async () => {
@ -294,7 +284,6 @@ describe.each([
await config.api.row.get(tableId, "1234567", { await config.api.row.get(tableId, "1234567", {
expectStatus: 404, expectStatus: 404,
}) })
await assertQueryUsage(queryUsage) // no change
}) })
isInternal && isInternal &&
@ -558,7 +547,6 @@ describe.each([
expect(savedRow.body.description).toEqual(existing.description) expect(savedRow.body.description).toEqual(existing.description)
expect(savedRow.body.name).toEqual("Updated Name") expect(savedRow.body.name).toEqual("Updated Name")
await assertRowUsage(rowUsage) await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage + 2) // account for the second load
}) })
it("should throw an error when given improper types", async () => { it("should throw an error when given improper types", async () => {
@ -578,7 +566,6 @@ describe.each([
) )
await assertRowUsage(rowUsage) await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage)
}) })
it("should not overwrite links if those links are not set", async () => { it("should not overwrite links if those links are not set", async () => {
@ -668,7 +655,6 @@ describe.each([
const res = await config.api.row.delete(table._id!, [createdRow]) const res = await config.api.row.delete(table._id!, [createdRow])
expect(res.body[0]._id).toEqual(createdRow._id) expect(res.body[0]._id).toEqual(createdRow._id)
await assertRowUsage(rowUsage - 1) await assertRowUsage(rowUsage - 1)
await assertQueryUsage(queryUsage + 1)
}) })
}) })
@ -687,7 +673,6 @@ describe.each([
expect(res.valid).toBe(true) expect(res.valid).toBe(true)
expect(Object.keys(res.errors)).toEqual([]) expect(Object.keys(res.errors)).toEqual([])
await assertRowUsage(rowUsage) await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage)
}) })
it("should errors on invalid row", async () => { it("should errors on invalid row", async () => {
@ -705,7 +690,6 @@ describe.each([
expect(Object.keys(res.errors)).toEqual([]) expect(Object.keys(res.errors)).toEqual([])
} }
await assertRowUsage(rowUsage) await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage)
}) })
}) })
@ -726,7 +710,6 @@ describe.each([
expect(res.body.length).toEqual(2) expect(res.body.length).toEqual(2)
await loadRow(row1._id!, table._id!, 404) await loadRow(row1._id!, table._id!, 404)
await assertRowUsage(rowUsage - 2) await assertRowUsage(rowUsage - 2)
await assertQueryUsage(queryUsage + 1)
}) })
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 () => {
@ -747,7 +730,6 @@ describe.each([
expect(res.body.length).toEqual(3) expect(res.body.length).toEqual(3)
await loadRow(row1._id!, table._id!, 404) await loadRow(row1._id!, table._id!, 404)
await assertRowUsage(rowUsage - 3) await assertRowUsage(rowUsage - 3)
await assertQueryUsage(queryUsage + 1)
}) })
it("should accept a valid row object and delete the row", async () => { it("should accept a valid row object and delete the row", async () => {
@ -760,7 +742,6 @@ describe.each([
expect(res.body.id).toEqual(row1._id) expect(res.body.id).toEqual(row1._id)
await loadRow(row1._id!, table._id!, 404) await loadRow(row1._id!, table._id!, 404)
await assertRowUsage(rowUsage - 1) await assertRowUsage(rowUsage - 1)
await assertQueryUsage(queryUsage + 1)
}) })
it("Should ignore malformed/invalid delete requests", async () => { it("Should ignore malformed/invalid delete requests", async () => {
@ -787,7 +768,6 @@ describe.each([
expect(res3.body.message).toEqual("Invalid delete rows request") expect(res3.body.message).toEqual("Invalid delete rows request")
await assertRowUsage(rowUsage) await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage)
}) })
}) })
@ -808,7 +788,6 @@ describe.each([
expect(res.body.length).toEqual(1) expect(res.body.length).toEqual(1)
expect(res.body[0]._id).toEqual(row._id) expect(res.body[0]._id).toEqual(row._id)
await assertRowUsage(rowUsage) await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage + 1)
}) })
it("should throw an error if view doesn't exist", async () => { it("should throw an error if view doesn't exist", async () => {
@ -818,7 +797,6 @@ describe.each([
await config.api.legacyView.get("derp", { expectStatus: 404 }) await config.api.legacyView.get("derp", { expectStatus: 404 })
await assertRowUsage(rowUsage) await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage)
}) })
it("should be able to run on a view", async () => { it("should be able to run on a view", async () => {
@ -837,7 +815,6 @@ describe.each([
expect(res.body[0]._id).toEqual(row._id) expect(res.body[0]._id).toEqual(row._id)
await assertRowUsage(rowUsage) await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage + 1)
}) })
}) })
@ -910,7 +887,6 @@ describe.each([
expect(resEnriched.body.link[0].name).toBe("Test Contact") expect(resEnriched.body.link[0].name).toBe("Test Contact")
expect(resEnriched.body.link[0].description).toBe("original description") expect(resEnriched.body.link[0].description).toBe("original description")
await assertRowUsage(rowUsage) await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage + 2)
}) })
}) })
@ -1129,7 +1105,6 @@ describe.each([
await config.api.row.delete(view.id, [createdRow]) await config.api.row.delete(view.id, [createdRow])
await assertRowUsage(rowUsage - 1) await assertRowUsage(rowUsage - 1)
await assertQueryUsage(queryUsage + 1)
await config.api.row.get(tableId, createdRow._id!, { await config.api.row.get(tableId, createdRow._id!, {
expectStatus: 404, expectStatus: 404,
@ -1157,7 +1132,6 @@ describe.each([
await config.api.row.delete(view.id, [rows[0], rows[2]]) await config.api.row.delete(view.id, [rows[0], rows[2]])
await assertRowUsage(rowUsage - 2) await assertRowUsage(rowUsage - 2)
await assertQueryUsage(queryUsage + 1)
await config.api.row.get(tableId, rows[0]._id!, { await config.api.row.get(tableId, rows[0]._id!, {
expectStatus: 404, expectStatus: 404,

800
yarn.lock

File diff suppressed because it is too large Load Diff