mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-22 19:11:33 +03:00
UBERF-8897 Use proper state when update collab doc activity (#7475)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
parent
413da21b50
commit
377fb908ba
@ -16,7 +16,7 @@
|
|||||||
import activity, { DocUpdateMessage } from '@hcengineering/activity'
|
import activity, { DocUpdateMessage } from '@hcengineering/activity'
|
||||||
import { loadCollabJson, loadCollabYdoc, saveCollabJson, saveCollabYdoc } from '@hcengineering/collaboration'
|
import { loadCollabJson, loadCollabYdoc, saveCollabJson, saveCollabYdoc } from '@hcengineering/collaboration'
|
||||||
import { decodeDocumentId } from '@hcengineering/collaborator-client'
|
import { decodeDocumentId } from '@hcengineering/collaborator-client'
|
||||||
import core, { AttachedData, MeasureContext, TxOperations } from '@hcengineering/core'
|
import core, { AttachedData, MeasureContext, Ref, Space, TxOperations } from '@hcengineering/core'
|
||||||
import { StorageAdapter } from '@hcengineering/server-core'
|
import { StorageAdapter } from '@hcengineering/server-core'
|
||||||
import { markupToYDocNoSchema, areEqualMarkups } from '@hcengineering/text'
|
import { markupToYDocNoSchema, areEqualMarkups } from '@hcengineering/text'
|
||||||
import { Doc as YDoc } from 'yjs'
|
import { Doc as YDoc } from 'yjs'
|
||||||
@ -173,6 +173,8 @@ export class PlatformStorageAdapter implements CollabStorageAdapter {
|
|||||||
await ctx.with('update', {}, () => client.diffUpdate(current, { [objectAttr]: blobId }))
|
await ctx.with('update', {}, () => client.diffUpdate(current, { [objectAttr]: blobId }))
|
||||||
|
|
||||||
await ctx.with('activity', {}, () => {
|
await ctx.with('activity', {}, () => {
|
||||||
|
const space = hierarchy.isDerived(current._class, core.class.Space) ? (current._id as Ref<Space>) : current.space
|
||||||
|
|
||||||
const data: AttachedData<DocUpdateMessage> = {
|
const data: AttachedData<DocUpdateMessage> = {
|
||||||
objectId,
|
objectId,
|
||||||
objectClass,
|
objectClass,
|
||||||
@ -189,7 +191,7 @@ export class PlatformStorageAdapter implements CollabStorageAdapter {
|
|||||||
}
|
}
|
||||||
return client.addCollection(
|
return client.addCollection(
|
||||||
activity.class.DocUpdateMessage,
|
activity.class.DocUpdateMessage,
|
||||||
current.space,
|
space,
|
||||||
current._id,
|
current._id,
|
||||||
current._class,
|
current._class,
|
||||||
'docUpdateMessages',
|
'docUpdateMessages',
|
||||||
|
95
workers/collaborator/src/metrics.ts
Normal file
95
workers/collaborator/src/metrics.ts
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
//
|
||||||
|
// Copyright © 2024 Hardcore Engineering Inc.
|
||||||
|
//
|
||||||
|
// Licensed under the Eclipse Public License, Version 2.0 (the 'License');
|
||||||
|
// you may not use this file except in compliance with the License. You may
|
||||||
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an 'AS IS' BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
//
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
import { type Env } from './env'
|
||||||
|
|
||||||
|
export async function withMetrics<T> (name: string, fn: (ctx: MetricsContext) => Promise<T>): Promise<T> {
|
||||||
|
const ctx = new MetricsContext()
|
||||||
|
|
||||||
|
const start = performance.now()
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await fn(ctx)
|
||||||
|
} finally {
|
||||||
|
const total = performance.now() - start
|
||||||
|
const ops = ctx.metrics
|
||||||
|
const message = `${name} total=${total} ` + ctx.toString()
|
||||||
|
console.log({ message, total, ops })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MetricsData {
|
||||||
|
op: string
|
||||||
|
time: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MetricsContext {
|
||||||
|
metrics: Array<MetricsData> = []
|
||||||
|
|
||||||
|
debug (...data: any[]): void {
|
||||||
|
console.debug(...data)
|
||||||
|
}
|
||||||
|
|
||||||
|
log (...data: any[]): void {
|
||||||
|
console.log(...data)
|
||||||
|
}
|
||||||
|
|
||||||
|
error (...data: any[]): void {
|
||||||
|
console.error(...data)
|
||||||
|
}
|
||||||
|
|
||||||
|
async with<T>(op: string, fn: () => Promise<T>): Promise<T> {
|
||||||
|
const start = performance.now()
|
||||||
|
try {
|
||||||
|
return await fn()
|
||||||
|
} finally {
|
||||||
|
const time = performance.now() - start
|
||||||
|
this.metrics.push({ op, time })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
withSync<T>(op: string, fn: () => T): T {
|
||||||
|
const start = performance.now()
|
||||||
|
try {
|
||||||
|
return fn()
|
||||||
|
} finally {
|
||||||
|
const time = performance.now() - start
|
||||||
|
this.metrics.push({ op, time })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toString (): string {
|
||||||
|
return this.metrics.map((p) => `${p.op}=${p.time}`).join(' ')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class LoggedDatalake {
|
||||||
|
constructor (
|
||||||
|
private readonly datalake: Env['DATALAKE'],
|
||||||
|
private readonly ctx: MetricsContext
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async getBlob (workspace: string, name: string): Promise<ArrayBuffer> {
|
||||||
|
return await this.ctx.with('datalake.getBlob', () => {
|
||||||
|
return this.datalake.getBlob(workspace, name)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async putBlob (workspace: string, name: string, data: ArrayBuffer | Blob | string, type: string): Promise<void> {
|
||||||
|
await this.ctx.with('datalake.putBlob', () => {
|
||||||
|
return this.datalake.putBlob(workspace, name, data, type)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user