Addressing PR comments.

This commit is contained in:
mike12345567 2024-05-16 13:27:54 +01:00
parent 94b85eeed0
commit 06d6d84b55
5 changed files with 22 additions and 26 deletions

View File

@ -5,13 +5,12 @@ import { DocumentType } from "@budibase/types"
enum ReplicationDirection {
TO_PRODUCTION = "toProduction",
TO_DEV = "toDev",
UNKNOWN = "unknown",
}
class Replication {
source: PouchDB.Database
target: PouchDB.Database
direction: ReplicationDirection
direction: ReplicationDirection | undefined
constructor({ source, target }: { source: string; target: string }) {
this.source = getPouchDB(source)
@ -26,8 +25,6 @@ class Replication {
target.startsWith(DocumentType.APP_DEV)
) {
this.direction = ReplicationDirection.TO_DEV
} else {
this.direction = ReplicationDirection.UNKNOWN
}
}

View File

@ -323,14 +323,16 @@ export class DatabaseImpl implements Database {
}
// checks design document is accurate (cleans up tables)
async sqlCleanup(): Promise<void> {
// this will check the design document and remove anything from
// disk which is not supposed to be there
async sqlDiskCleanup(): Promise<void> {
const dbName = this.name
const url = `/${dbName}/_cleanup`
return await this._sqlQuery<void>(url, "POST")
}
// removes a document from sqlite
async sqlPurge(docIds: string[] | string): Promise<void> {
async sqlPurgeDocument(docIds: string[] | string): Promise<void> {
if (!Array.isArray(docIds)) {
docIds = [docIds]
}
@ -359,7 +361,7 @@ export class DatabaseImpl implements Database {
)
await this.remove(SQLITE_DESIGN_DOC_ID, definition._rev)
} finally {
await this.sqlCleanup()
await this.sqlDiskCleanup()
}
}
return await this.nano().db.destroy(this.name)

View File

@ -56,19 +56,16 @@ export class DDInstrumentedDatabase implements Database {
})
}
remove(idOrDoc: Document): Promise<DocumentDestroyResponse>
remove(idOrDoc: string, rev?: string): Promise<DocumentDestroyResponse>
remove(
id: string | Document,
rev?: string | undefined
idOrDoc: string | Document,
rev?: string
): Promise<DocumentDestroyResponse> {
return tracer.trace("db.remove", span => {
span?.addTags({ db_name: this.name, doc_id: id })
if (typeof id === "object") {
return this.db.remove(id)
} else if (rev) {
span?.addTags({ db_name: this.name, doc_id: idOrDoc })
const id: string = typeof idOrDoc === "object" ? idOrDoc._id! : idOrDoc
return this.db.remove(id, rev)
} else {
throw new Error("No revision supplied for removal")
}
})
}
@ -167,17 +164,17 @@ export class DDInstrumentedDatabase implements Database {
})
}
sqlPurge(docIds: string[] | string): Promise<void> {
return tracer.trace("db.sqlPurge", span => {
sqlPurgeDocument(docIds: string[] | string): Promise<void> {
return tracer.trace("db.sqlPurgeDocument", span => {
span?.addTags({ db_name: this.name })
return this.db.sqlPurge(docIds)
return this.db.sqlPurgeDocument(docIds)
})
}
sqlCleanup(): Promise<void> {
return tracer.trace("db.sqlCleanup", span => {
sqlDiskCleanup(): Promise<void> {
return tracer.trace("db.sqlDiskCleanup", span => {
span?.addTags({ db_name: this.name })
return this.db.sqlCleanup()
return this.db.sqlDiskCleanup()
})
}
}

View File

@ -146,7 +146,7 @@ export async function removeTable(table: Table) {
delete definition.sql.tables[table._id!]
await db.put(definition)
// make sure SQS is cleaned up, tables removed
await db.sqlCleanup()
await db.sqlDiskCleanup()
}
} catch (err: any) {
if (err?.status === 404) {

View File

@ -146,8 +146,8 @@ export interface Database {
sql: string,
parameters?: SqlQueryBinding
): Promise<T[]>
sqlPurge(docIds: string[] | string): Promise<void>
sqlCleanup(): Promise<void>
sqlPurgeDocument(docIds: string[] | string): Promise<void>
sqlDiskCleanup(): Promise<void>
allDocs<T extends Document | RowValue>(
params: DatabaseQueryOpts
): Promise<AllDocsResponse<T>>