From 879a62c989abbe4aed4b624086e2a3c7238891f0 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Tue, 10 May 2022 21:59:39 +0100 Subject: [PATCH] Add query quota increment to rows CRUD --- .../server/src/api/controllers/row/index.ts | 34 +++++++++++-------- packages/server/yarn.lock | 18 +++++----- packages/worker/yarn.lock | 18 +++++----- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index c50fef496e..27810008d3 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -31,7 +31,9 @@ export async function patch(ctx: any): Promise { return save(ctx) } try { - const { row, table } = await pickApi(tableId).patch(ctx) + const { row, table } = await quotas.addQuery(() => + pickApi(tableId).patch(ctx) + ) ctx.status = 200 ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:update`, appId, row, table) @@ -42,7 +44,7 @@ export async function patch(ctx: any): Promise { } } -const saveRow = async (ctx: any) => { +export const save = async (ctx: any) => { const appId = ctx.appId const tableId = getTableId(ctx) const body = ctx.request.body @@ -51,7 +53,9 @@ const saveRow = async (ctx: any) => { return patch(ctx) } try { - const { row, table } = await pickApi(tableId).save(ctx) + const { row, table } = await quotas.addRow(() => + quotas.addQuery(() => pickApi(tableId).save(ctx)) + ) ctx.status = 200 ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table) ctx.message = `${table.name} saved successfully` @@ -61,14 +65,10 @@ const saveRow = async (ctx: any) => { } } -export async function save(ctx: any) { - await quotas.addRow(() => saveRow(ctx)) -} - export async function fetchView(ctx: any) { const tableId = getTableId(ctx) try { - ctx.body = await pickApi(tableId).fetchView(ctx) + ctx.body = await quotas.addQuery(() => pickApi(tableId).fetchView(ctx)) } catch (err) { ctx.throw(400, err) } @@ -77,7 +77,7 @@ export async function fetchView(ctx: any) { export async function fetch(ctx: any) { const tableId = getTableId(ctx) try { - ctx.body = await pickApi(tableId).fetch(ctx) + ctx.body = await quotas.addQuery(() => pickApi(tableId).fetch(ctx)) } catch (err) { ctx.throw(400, err) } @@ -86,7 +86,7 @@ export async function fetch(ctx: any) { export async function find(ctx: any) { const tableId = getTableId(ctx) try { - ctx.body = await pickApi(tableId).find(ctx) + ctx.body = await quotas.addQuery(() => pickApi(tableId).find(ctx)) } catch (err) { ctx.throw(400, err) } @@ -98,14 +98,16 @@ export async function destroy(ctx: any) { const tableId = getTableId(ctx) let response, row if (inputs.rows) { - let { rows } = await pickApi(tableId).bulkDestroy(ctx) + let { rows } = await quotas.addQuery(() => + pickApi(tableId).bulkDestroy(ctx) + ) await quotas.removeRows(rows.length) response = rows for (let row of rows) { ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row) } } else { - let resp = await pickApi(tableId).destroy(ctx) + let resp = await quotas.addQuery(() => pickApi(tableId).destroy(ctx)) await quotas.removeRow() response = resp.response row = resp.row @@ -121,7 +123,7 @@ export async function search(ctx: any) { const tableId = getTableId(ctx) try { ctx.status = 200 - ctx.body = await pickApi(tableId).search(ctx) + ctx.body = await quotas.addQuery(() => pickApi(tableId).search(ctx)) } catch (err) { ctx.throw(400, err) } @@ -139,7 +141,9 @@ export async function validate(ctx: any) { export async function fetchEnrichedRow(ctx: any) { const tableId = getTableId(ctx) try { - ctx.body = await pickApi(tableId).fetchEnrichedRow(ctx) + ctx.body = await quotas.addQuery(() => + pickApi(tableId).fetchEnrichedRow(ctx) + ) } catch (err) { ctx.throw(400, err) } @@ -148,7 +152,7 @@ export async function fetchEnrichedRow(ctx: any) { export const exportRows = async (ctx: any) => { const tableId = getTableId(ctx) try { - ctx.body = await pickApi(tableId).exportRows(ctx) + ctx.body = await quotas.addQuery(() => pickApi(tableId).exportRows(ctx)) } catch (err) { ctx.throw(400, err) } diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index f9b414118f..9dd96cbd09 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -1014,10 +1014,10 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@budibase/backend-core@1.0.147": - version "1.0.147" - resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.147.tgz#fc93a803e97e304170b33bd28b4f5deda32bec18" - integrity sha512-0GcF9G/tTAsko9g352MB8K3EtMTVb7v7Av6RdsYyKBdVtOD42HKFzSOD0n/RQUL4v70YByiu99zJAB6z1m1Pcg== +"@budibase/backend-core@1.0.149": + version "1.0.149" + resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.149.tgz#44e00dc718ef3f5c2f8021a13799c05b89f03cfa" + integrity sha512-RudWkU6I+AoiARKcjDAKYmKgpW99VAmw8cULyL2QexFtrJaPwRX6UXDqP3Et887rAN+ee3t3tFIWEui51LAVPg== dependencies: "@techpass/passport-openidconnect" "^0.3.0" aws-sdk "^2.901.0" @@ -1091,12 +1091,12 @@ svelte-flatpickr "^3.2.3" svelte-portal "^1.0.0" -"@budibase/pro@1.0.147": - version "1.0.147" - resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.147.tgz#c1ec9d92ffaa40285a83c57ddbec1f32802cd9a1" - integrity sha512-e4im6Byqeeit/QFHkVhVdRmgIlJJY/W06cQrOuiG/1ngO4PGnXeJqtjQjHVfvchD5Xi3y1MgQ4AtH2Bzb5LEhw== +"@budibase/pro@1.0.149": + version "1.0.149" + resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.149.tgz#6d3cc93635baffad4f425576c452bf9b8c6eb15e" + integrity sha512-zS+xIezmcJEB2yXzwSNI0OVDmFsBtE4r8ZVHKw+pGo1KqdJ1i11DEsfoAp9VxKOoo1ENDultujALfZQYlesMww== dependencies: - "@budibase/backend-core" "1.0.147" + "@budibase/backend-core" "1.0.149" node-fetch "^2.6.1" "@budibase/standard-components@^0.9.139": diff --git a/packages/worker/yarn.lock b/packages/worker/yarn.lock index 80f2996bec..c0a3bd76ce 100644 --- a/packages/worker/yarn.lock +++ b/packages/worker/yarn.lock @@ -293,10 +293,10 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@budibase/backend-core@1.0.147": - version "1.0.147" - resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.147.tgz#fc93a803e97e304170b33bd28b4f5deda32bec18" - integrity sha512-0GcF9G/tTAsko9g352MB8K3EtMTVb7v7Av6RdsYyKBdVtOD42HKFzSOD0n/RQUL4v70YByiu99zJAB6z1m1Pcg== +"@budibase/backend-core@1.0.149": + version "1.0.149" + resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.149.tgz#44e00dc718ef3f5c2f8021a13799c05b89f03cfa" + integrity sha512-RudWkU6I+AoiARKcjDAKYmKgpW99VAmw8cULyL2QexFtrJaPwRX6UXDqP3Et887rAN+ee3t3tFIWEui51LAVPg== dependencies: "@techpass/passport-openidconnect" "^0.3.0" aws-sdk "^2.901.0" @@ -321,12 +321,12 @@ uuid "^8.3.2" zlib "^1.0.5" -"@budibase/pro@1.0.147": - version "1.0.147" - resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.147.tgz#c1ec9d92ffaa40285a83c57ddbec1f32802cd9a1" - integrity sha512-e4im6Byqeeit/QFHkVhVdRmgIlJJY/W06cQrOuiG/1ngO4PGnXeJqtjQjHVfvchD5Xi3y1MgQ4AtH2Bzb5LEhw== +"@budibase/pro@1.0.149": + version "1.0.149" + resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.149.tgz#6d3cc93635baffad4f425576c452bf9b8c6eb15e" + integrity sha512-zS+xIezmcJEB2yXzwSNI0OVDmFsBtE4r8ZVHKw+pGo1KqdJ1i11DEsfoAp9VxKOoo1ENDultujALfZQYlesMww== dependencies: - "@budibase/backend-core" "1.0.147" + "@budibase/backend-core" "1.0.149" node-fetch "^2.6.1" "@cspotcode/source-map-consumer@0.8.0":