1
0
Fork 0
mirror of synced 2024-10-02 10:08:09 +13:00

Merge branch 'master' into feature/app-list-actions

This commit is contained in:
deanhannigan 2024-03-08 14:44:08 +00:00 committed by GitHub
commit 66f0deecae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 43 additions and 5 deletions

View file

@ -10,6 +10,7 @@ interface ProcessDocMessage {
}
const PERSIST_MAX_ATTEMPTS = 100
let processor: DocWritethroughProcessor | undefined
export const docWritethroughProcessorQueue = createQueue<ProcessDocMessage>(
JobQueue.DOC_WRITETHROUGH_QUEUE,
@ -61,8 +62,6 @@ class DocWritethroughProcessor {
}
}
export const processor = new DocWritethroughProcessor().init()
export class DocWritethrough {
private db: Database
private _docId: string
@ -84,3 +83,15 @@ export class DocWritethrough {
})
}
}
export function init(): DocWritethroughProcessor {
processor = new DocWritethroughProcessor().init()
return processor
}
export function getProcessor(): DocWritethroughProcessor {
if (!processor) {
return init()
}
return processor
}

View file

@ -7,6 +7,7 @@ import { getDB } from "../../db"
import {
DocWritethrough,
docWritethroughProcessorQueue,
init,
} from "../docWritethrough"
import InMemoryQueue from "../../queue/inMemoryQueue"
@ -19,6 +20,10 @@ async function waitForQueueCompletion() {
}
describe("docWritethrough", () => {
beforeAll(() => {
init()
})
const config = new DBTestConfiguration()
const db = getDB(structures.db.id())

View file

@ -1,11 +1,12 @@
import { context } from "@budibase/backend-core"
import { isExternalTableID } from "../../../integrations/utils"
import { APP_PREFIX, DocumentType } from "../../../db/utils"
import { Row } from "@budibase/types"
export async function addRev(
body: { _id?: string; _rev?: string },
tableId?: string
) {
): Promise<Row> {
if (!body._id || (tableId && isExternalTableID(tableId))) {
return body
}

View file

@ -128,7 +128,10 @@ export async function bulkDestroy(ctx: UserCtx) {
)
}
const responses = await Promise.all(promises)
return { response: { ok: true }, rows: responses.map(resp => resp.row) }
const finalRows = responses
.map(resp => resp.row)
.filter(row => row && row._id)
return { response: { ok: true }, rows: finalRows }
}
export async function fetchEnrichedRow(ctx: UserCtx) {

View file

@ -131,7 +131,10 @@ async function processDeleteRowsRequest(ctx: UserCtx<DeleteRowRequest>) {
: fixRow(processedRow, ctx.params)
})
return await Promise.all(processedRows)
const responses = await Promise.allSettled(processedRows)
return responses
.filter(resp => resp.status === "fulfilled")
.map(resp => (resp as PromiseFulfilledResult<Row>).value)
}
async function deleteRows(ctx: UserCtx<DeleteRowRequest>) {

View file

@ -636,6 +636,17 @@ describe.each([
expect(res[0]._id).toEqual(createdRow._id)
await assertRowUsage(rowUsage - 1)
})
it("should be able to bulk delete rows, including a row that doesn't exist", async () => {
const createdRow = await config.createRow()
const res = await config.api.row.bulkDelete(table._id!, {
rows: [createdRow, { _id: "2" }],
})
expect(res[0]._id).toEqual(createdRow._id)
expect(res.length).toEqual(1)
})
})
describe("validate", () => {

View file

@ -7,6 +7,7 @@ import {
logging,
tenancy,
users,
cache,
} from "@budibase/backend-core"
import fs from "fs"
import { watch } from "./watch"
@ -74,6 +75,7 @@ export async function startup(app?: Koa, server?: Server) {
eventEmitter.emitPort(env.PORT)
fileSystem.init()
await redis.init()
cache.docWritethrough.init()
eventInit()
if (app && server) {
initialiseWebsockets(app, server)

View file

@ -17,6 +17,7 @@ import {
env as coreEnv,
timers,
redis,
cache,
} from "@budibase/backend-core"
db.init()
@ -90,6 +91,7 @@ export default server.listen(parseInt(env.PORT || "4002"), async () => {
console.log(`Worker running on ${JSON.stringify(server.address())}`)
await initPro()
await redis.clients.init()
cache.docWritethrough.init()
// configure events to use the pro audit log write
// can't integrate directly into backend-core due to cyclic issues
await events.processors.init(proSdk.auditLogs.write)