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:
restart: unless-stopped
image: redis
command: redis-server --requirepass ${REDIS_PASSWORD}
command: redis-server --requirepass "${REDIS_PASSWORD}"
volumes:
- redis_data:/data

View File

@ -2,7 +2,6 @@ import Redlock from "redlock"
import { getLockClient } from "./init"
import { LockOptions, LockType } from "@budibase/types"
import * as context from "../context"
import { logWarn } from "../logging"
import { utils } from "@budibase/shared-core"
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 },
},
}
const runFn = () => Runner.run(inputs)
const { rows, keys, info, extra } = await quotas.addQuery<any>(runFn, {
datasourceId: datasource._id,
})
const { rows, keys, info, extra } = (await Runner.run(inputs)) as any
const schemaFields: any = {}
if (rows?.length > 0) {
for (let key of [...new Set(keys)] as string[]) {
@ -259,14 +256,8 @@ async function execute(
},
schema: query.schema,
}
const runFn = () => Runner.run(inputs)
const { rows, pagination, extra, info } = await quotas.addQuery<any>(
runFn,
{
datasourceId: datasource._id,
}
)
const { rows, pagination, extra, info } = (await Runner.run(inputs)) as any
// remove the raw from execution incase transformer being used to hide data
if (extra?.raw) {
delete extra.raw

View File

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

View File

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

View File

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

800
yarn.lock

File diff suppressed because it is too large Load Diff