mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-30 21:45:01 +02:00
Merge staging feb4 (#7910)
This commit is contained in:
@@ -22,6 +22,7 @@ import core, {
|
||||
type Class,
|
||||
type Doc,
|
||||
type DocumentQuery,
|
||||
type Domain,
|
||||
type FindOptions,
|
||||
type FindResult,
|
||||
type Hierarchy,
|
||||
@@ -90,6 +91,11 @@ class BenchmarkDbAdapter extends DummyDbAdapter {
|
||||
return toFindResult<T>(result as T[])
|
||||
}
|
||||
|
||||
getDomainHash (ctx: MeasureContext, domain: Domain): Promise<string> {
|
||||
// Since benchmark coult not be changed.
|
||||
return Promise.resolve('')
|
||||
}
|
||||
|
||||
tx (ctx: MeasureContext, ...tx: Tx[]): Promise<TxResult[]> {
|
||||
if (benchData === '') {
|
||||
benchData = genData(1024 * 1024)
|
||||
|
||||
@@ -37,7 +37,6 @@ import core, {
|
||||
type WorkspaceIds
|
||||
} from '@hcengineering/core'
|
||||
import { type DbAdapter, type DbAdapterHandler, type DomainHelperOperations } from './adapter'
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
@@ -102,6 +101,11 @@ export class DummyDbAdapter implements DbAdapter {
|
||||
|
||||
async clean (ctx: MeasureContext, domain: Domain, docs: Ref<Doc>[]): Promise<void> {}
|
||||
|
||||
getDomainHash (ctx: MeasureContext, domain: Domain): Promise<string> {
|
||||
// Return '' for empty documents content.
|
||||
return Promise.resolve('')
|
||||
}
|
||||
|
||||
async update<T extends Doc>(
|
||||
ctx: MeasureContext,
|
||||
domain: Domain,
|
||||
|
||||
@@ -88,6 +88,10 @@ export class BackupClientOps {
|
||||
})
|
||||
}
|
||||
|
||||
getDomainHash (ctx: MeasureContext, domain: Domain): Promise<string> {
|
||||
return this.storage.getDomainHash(ctx, domain)
|
||||
}
|
||||
|
||||
closeChunk (ctx: MeasureContext, idx: number): Promise<void> {
|
||||
return ctx.with('close-chunk', {}, async () => {
|
||||
const chunk = this.chunkInfo.get(idx)
|
||||
|
||||
@@ -572,6 +572,8 @@ export interface Session {
|
||||
searchFulltext: (ctx: ClientSessionCtx, query: SearchQuery, options: SearchOptions) => Promise<void>
|
||||
tx: (ctx: ClientSessionCtx, tx: Tx) => Promise<void>
|
||||
loadChunk: (ctx: ClientSessionCtx, domain: Domain, idx?: number) => Promise<void>
|
||||
|
||||
getDomainHash: (ctx: ClientSessionCtx, domain: Domain) => Promise<void>
|
||||
closeChunk: (ctx: ClientSessionCtx, idx: number) => Promise<void>
|
||||
loadDocs: (ctx: ClientSessionCtx, domain: Domain, docs: Ref<Doc>[]) => Promise<void>
|
||||
upload: (ctx: ClientSessionCtx, domain: Domain, docs: Doc[]) => Promise<void>
|
||||
|
||||
@@ -31,7 +31,7 @@ import core, {
|
||||
type PersonUuid
|
||||
} from '@hcengineering/core'
|
||||
import { PlatformError, unknownError } from '@hcengineering/platform'
|
||||
import { type Hash } from 'crypto'
|
||||
import { createHash, type Hash } from 'crypto'
|
||||
import fs from 'fs'
|
||||
import type { DbAdapter } from './adapter'
|
||||
import { BackupClientOps } from './storage'
|
||||
@@ -262,6 +262,7 @@ export function wrapPipeline (ctx: MeasureContext, pipeline: Pipeline, wsIds: Wo
|
||||
getHierarchy: () => pipeline.context.hierarchy,
|
||||
getModel: () => pipeline.context.modelDb,
|
||||
loadChunk: (domain, idx) => backupOps.loadChunk(ctx, domain, idx),
|
||||
getDomainHash: (domain) => backupOps.getDomainHash(ctx, domain),
|
||||
loadDocs: (domain, docs) => backupOps.loadDocs(ctx, domain, docs),
|
||||
upload: (domain, docs) => backupOps.upload(ctx, domain, docs),
|
||||
searchFulltext: async (query, options) => ({ docs: [], total: 0 }),
|
||||
@@ -310,6 +311,10 @@ export function wrapAdapterToClient (ctx: MeasureContext, storageAdapter: DbAdap
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
|
||||
async getDomainHash (domain: Domain): Promise<string> {
|
||||
return await storageAdapter.getDomainHash(ctx, domain)
|
||||
}
|
||||
|
||||
async closeChunk (idx: number): Promise<void> {}
|
||||
|
||||
async loadDocs (domain: Domain, docs: Ref<Doc>[]): Promise<Doc[]> {
|
||||
@@ -328,3 +333,31 @@ export function wrapAdapterToClient (ctx: MeasureContext, storageAdapter: DbAdap
|
||||
}
|
||||
return new TestClientConnection()
|
||||
}
|
||||
|
||||
export async function calcHashHash (ctx: MeasureContext, domain: Domain, adapter: DbAdapter): Promise<string> {
|
||||
const hash = createHash('sha256')
|
||||
|
||||
const it = adapter.find(ctx, domain)
|
||||
|
||||
try {
|
||||
let count = 0
|
||||
while (true) {
|
||||
const part = await it.next(ctx)
|
||||
if (part.length === 0) {
|
||||
break
|
||||
}
|
||||
count += part.length
|
||||
for (const doc of part) {
|
||||
hash.update(doc.id)
|
||||
hash.update(doc.hash)
|
||||
}
|
||||
}
|
||||
if (count === 0) {
|
||||
// Use empty hash for empty documents.
|
||||
return ''
|
||||
}
|
||||
return hash.digest('hex')
|
||||
} finally {
|
||||
await it.close(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user