Skip to content

Commit

Permalink
Speedup isDerived and fix auto join channels doc state
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
  • Loading branch information
haiodo committed Aug 17, 2024
1 parent 67e2f8e commit 00c49ca
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"ACCOUNT_PORT": "3000",
"FRONT_URL": "http://localhost:8080",
"outputCapture": "std",
"SES_URL": "http://localhost:8091",
"SES_URL": "",
"MINIO_ACCESS_KEY": "minioadmin",
"MINIO_SECRET_KEY": "minioadmin",
"MINIO_ENDPOINT": "localhost"
Expand Down
4 changes: 2 additions & 2 deletions dev/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ services:
- LAST_NAME_FIRST=true
- ACCOUNTS_URL=http://localhost:3000
- BRANDING_PATH=/var/cfg/branding.json
- INIT_SCRIPT_URL=https://raw.githubusercontent.com/hcengineering/init/main/script.yaml
- INIT_WORKSPACE=onboarding
# - INIT_SCRIPT_URL=https://raw.githubusercontent.com/hcengineering/init/main/script.yaml
# - INIT_WORKSPACE=onboarding
restart: unless-stopped
collaborator:
image: hardcoreeng/collaborator
Expand Down
28 changes: 11 additions & 17 deletions packages/core/src/hierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class Hierarchy {
private readonly attributes = new Map<Ref<Classifier>, Map<string, AnyAttribute>>()
private readonly attributesById = new Map<Ref<AnyAttribute>, AnyAttribute>()
private readonly descendants = new Map<Ref<Classifier>, Ref<Classifier>[]>()
private readonly ancestors = new Map<Ref<Classifier>, Ref<Classifier>[]>()
private readonly ancestors = new Map<Ref<Classifier>, { ordered: Ref<Classifier>[], set: Set<Ref<Classifier>> }>()
private readonly proxies = new Map<Ref<Mixin<Doc>>, ProxyHandler<Doc>>()

private readonly classifierProperties = new Map<Ref<Classifier>, Record<string, any>>()
Expand Down Expand Up @@ -166,7 +166,7 @@ export class Hierarchy {
if (result === undefined) {
throw new Error('ancestors not found: ' + _class)
}
return result
return result.ordered
}

getClass<T extends Obj = Obj>(_class: Ref<Class<T>>): Class<T> {
Expand Down Expand Up @@ -301,17 +301,7 @@ export class Hierarchy {
* It will iterate over parents.
*/
isDerived<T extends Obj>(_class: Ref<Class<T>>, from: Ref<Class<T>>): boolean {
let cl: Ref<Class<T>> | undefined = _class
while (cl !== undefined) {
if (cl === from) return true

const cll = this.classifiers.get(cl)
if (cll === undefined || this.isInterface(cll)) {
return false
}
cl = (cll as Class<T>).extends
}
return false
return this.ancestors.get(_class)?.set?.has(from) ?? false
}

/**
Expand Down Expand Up @@ -398,15 +388,19 @@ export class Hierarchy {
const list = this.ancestors.get(_class)
if (list === undefined) {
if (add) {
this.ancestors.set(_class, [classifier])
this.ancestors.set(_class, { ordered: [classifier], set: new Set([classifier]) })
}
} else {
if (add) {
addIf(list, classifier)
if (!list.set.has(classifier)) {
list.ordered.push(classifier)
list.set.add(classifier)
}
} else {
const pos = list.indexOf(classifier)
const pos = list.ordered.indexOf(classifier)
if (pos !== -1) {
list.splice(pos, 1)
list.ordered.splice(pos, 1)
list.set.delete(classifier)
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions packages/text/src/markup/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import { Editor, Extensions, getSchema } from '@tiptap/core'
import { generateHTML, generateJSON } from '@tiptap/html'
import { Node as ProseMirrorNode, Schema } from '@tiptap/pm/model'

import { deepEqual } from 'fast-equals'
import { defaultExtensions } from '../extensions'
import { MarkupMark, MarkupNode, MarkupNodeType, emptyMarkupNode } from './model'
import { nodeDoc, nodeParagraph, nodeText } from './dsl'
import { deepEqual } from 'fast-equals'
import { MarkupMark, MarkupNode, MarkupNodeType, emptyMarkupNode } from './model'

/** @public */
export const EmptyMarkup: Markup = jsonToMarkup(emptyMarkupNode())
Expand Down Expand Up @@ -226,9 +226,11 @@ export function pmNodeToHTML (node: ProseMirrorNode, extensions?: Extensions): s
const ELLIPSIS_CHAR = '…'
const WHITESPACE = ' '

const defaultSchema = getSchema(defaultExtensions)

/** @public */
export function stripTags (markup: Markup, textLimit = 0, extensions: Extensions | undefined = undefined): string {
const schema = getSchema(extensions ?? defaultExtensions)
const schema = extensions === undefined ? defaultSchema : getSchema(extensions)
const parsed = markupToPmNode(markup, schema)

const textParts: string[] = []
Expand Down
10 changes: 6 additions & 4 deletions packages/text/src/ydoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ export function yDocContentToNode (
return yDocToNode(ydoc, field, schema, extensions)
}

const defaultSchema = getSchema(defaultExtensions)

/**
* Get ProseMirror node from Y.Doc
*
* @public
*/
export function yDocToNode (ydoc: YDoc, field?: string, schema?: Schema, extensions?: Extensions): Node {
schema ??= getSchema(extensions ?? defaultExtensions)
schema ??= extensions === undefined ? defaultSchema : getSchema(extensions ?? defaultExtensions)

try {
const body = yDocToProsemirrorJSON(ydoc, field)
Expand All @@ -79,7 +81,7 @@ export function yDocToNode (ydoc: YDoc, field?: string, schema?: Schema, extensi
* @public
*/
export function yDocContentToNodes (content: ArrayBuffer, schema?: Schema, extensions?: Extensions): Node[] {
schema ??= getSchema(extensions ?? defaultExtensions)
schema ??= extensions === undefined ? defaultSchema : getSchema(extensions ?? defaultExtensions)

const nodes: Node[] = []

Expand Down Expand Up @@ -112,7 +114,7 @@ export function updateYDocContent (
schema?: Schema,
extensions?: Extensions
): YDoc | undefined {
schema ??= getSchema(extensions ?? defaultExtensions)
schema ??= extensions === undefined ? defaultSchema : getSchema(extensions ?? defaultExtensions)

try {
const ydoc = new YDoc()
Expand Down Expand Up @@ -140,7 +142,7 @@ export function updateYDocContent (
* @public
*/
export function YDocFromContent (content: MarkupNode, field: string, schema?: Schema, extensions?: Extensions): YDoc {
schema ??= getSchema(extensions ?? defaultExtensions)
schema ??= extensions === undefined ? defaultSchema : getSchema(extensions ?? defaultExtensions)

const res = new YDoc({ gc: false })

Expand Down
3 changes: 2 additions & 1 deletion server/account/src/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,7 @@ async function createPersonAccount (
client ??
(await connect(getEndpoint(ctx, workspaceInfo, EndpointKind.Internal), getWorkspaceId(workspace, productId)))
try {
const ops = new TxOperations(connection, core.account.System)
const ops = new TxOperations(connection, core.account.System).apply('create-person' + generateId())

const name = combineName(account.first, account.last)
// Check if PersonAccount is not exists
Expand Down Expand Up @@ -2033,6 +2033,7 @@ async function createPersonAccount (
}
}
}
await ops.commit()
} finally {
if (client === undefined) {
await connection.close()
Expand Down
13 changes: 5 additions & 8 deletions server/core/src/server/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,8 @@ export class TServerStorage implements ServerStorage {
findAll(mctx, clazz, query, options)

const removed = await ctx.with('process-remove', {}, (ctx) => this.processRemove(ctx, txes, findAll))
const collections = ctx.with('process-collection', {}, (ctx) => this.processCollection(ctx, txes, findAll))
const moves = ctx.with('process-move', {}, (ctx) => this.processMove(ctx.ctx, txes, findAll))
const collections = await ctx.with('process-collection', {}, (ctx) => this.processCollection(ctx, txes, findAll))
const moves = await ctx.with('process-move', {}, (ctx) => this.processMove(ctx.ctx, txes, findAll))

const applyTxes: Tx[] = []

Expand Down Expand Up @@ -869,7 +869,7 @@ export class TServerStorage implements ServerStorage {
{ count: txes.length }
)

const derived = [...removed, ...(await collections), ...(await moves), ...triggers]
const derived = [...removed, ...collections, ...moves, ...triggers]

return await this.processDerivedTxes(derived, ctx, findAll)
}
Expand All @@ -879,15 +879,12 @@ export class TServerStorage implements ServerStorage {
ctx: SessionOperationContext,
findAll: ServerStorage['findAll']
): Promise<Tx[]> {
derived.sort((a, b) => a.modifiedOn - b.modifiedOn)

const routePromise = ctx.with('derived-route-tx', {}, (ctx) => this.routeTx(ctx, ...derived))

const nestedTxes: Tx[] = []
if (derived.length > 0) {
derived.sort((a, b) => a.modifiedOn - b.modifiedOn)
await ctx.with('derived-route-tx', {}, (ctx) => this.routeTx(ctx, ...derived))
nestedTxes.push(...(await this.processDerived(ctx, derived, findAll)))
}
await routePromise

const res = [...derived, ...nestedTxes]

Expand Down

0 comments on commit 00c49ca

Please sign in to comment.