Skip to content

Commit 85d1d63

Browse files
committed
Few fixes
Signed-off-by: Andrey Sobolev <[email protected]>
1 parent c81adb3 commit 85d1d63

File tree

8 files changed

+97
-16
lines changed

8 files changed

+97
-16
lines changed

dev/docker-compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ services:
301301
environment:
302302
- QUEUE_CONFIG=${QUEUE_CONFIG}
303303
- REGION=
304+
- ENDPOINT=ws://huly.local:3333
304305
- SERVER_PORT=3333
305306
- SERVER_SECRET=secret
306307
- ENABLE_COMPRESSION=true
@@ -337,6 +338,7 @@ services:
337338
- QUEUE_CONFIG=${QUEUE_CONFIG}
338339
- SERVER_PORT=3332
339340
- REGION=cockroach
341+
- ENDPOINT=ws://huly.local:3332
340342
- SERVER_SECRET=secret
341343
- ENABLE_COMPRESSION=true
342344
- FULLTEXT_URL=http://huly.local:4702

dev/tool/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,14 +1363,15 @@ export function devTool (
13631363

13641364
program
13651365
.command('backup-s3-download <bucketName> <dirName> <storeIn>')
1366+
.option('-s, --skip <skip>', 'A list of ; separated domain names to skip during backup', '')
13661367
.description('Download a full backup from s3 to local dir')
1367-
.action(async (bucketName: string, dirName: string, storeIn: string, cmd) => {
1368+
.action(async (bucketName: string, dirName: string, storeIn: string, cmd: { skip: string }) => {
13681369
const backupStorageConfig = storageConfigFromEnv(process.env.STORAGE)
13691370
const storageAdapter = createStorageFromConfig(backupStorageConfig.storages[0])
13701371
const backupIds = { uuid: bucketName as WorkspaceUuid, dataId: bucketName as WorkspaceDataId, url: '' }
13711372
try {
13721373
const storage = await createStorageBackupStorage(toolCtx, storageAdapter, backupIds, dirName)
1373-
await backupDownload(storage, storeIn)
1374+
await backupDownload(storage, storeIn, new Set(cmd.skip.split(';')))
13741375
} catch (err: any) {
13751376
toolCtx.error('failed to size backup', { err })
13761377
}

plugins/client-resources/src/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ class Connection implements ClientConnection {
512512
}
513513
}
514514
this.handlers.forEach((handler) => {
515-
handler(...txArr)
515+
handler(txArr)
516516
})
517517

518518
clearTimeout(this.incomingTimer)

pods/server/src/__start.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import serverToken from '@hcengineering/server-token'
2525
import { join } from 'path'
2626
import { start } from '.'
2727
import { profileStart, profileStop } from './inspector'
28+
import client from '@hcengineering/client'
29+
import { WebSocket } from 'ws'
2830

2931
configureAnalytics(process.env.SENTRY_DSN, {})
3032
Analytics.setTag('application', 'transactor')
@@ -87,6 +89,10 @@ setMetadata(serverCalendar.metadata.EndpointURL, process.env.CALENDAR_URL)
8789
const region = process.env.REGION ?? ''
8890
const endpointName = process.env.ENDPOINT_NAME ?? `ws://huly.local:${config.serverPort}`
8991

92+
setMetadata(client.metadata.ClientSocketFactory, (url) => {
93+
return new WebSocket(url) as any
94+
})
95+
9096
const { shutdown, sessionManager } = start(metricsContext, config.dbUrl, {
9197
fulltextUrl: config.fulltextUrl,
9298
storageConfig,

server/account/src/operations.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import core, {
2727
type PersonId,
2828
type PersonUuid,
2929
SocialIdType,
30+
systemAccount,
3031
systemAccountUuid,
3132
type WorkspaceMemberInfo,
3233
type WorkspaceUuid
@@ -1448,12 +1449,22 @@ export async function getLoginWithWorkspaceInfo (
14481449
throw new PlatformError(new Status(Severity.ERROR, platform.status.InternalServerError, {}))
14491450
}
14501451

1451-
const account = await db.account.findOne({ uuid: accountUuid })
1452+
const account = (accountUuid === systemAccountUuid) ? systemAccount : await db.account.findOne({ uuid: accountUuid })
14521453

14531454
if (account == null) {
14541455
throw new PlatformError(new Status(Severity.ERROR, platform.status.InternalServerError, {}))
14551456
}
14561457

1458+
if (accountUuid === systemAccountUuid) {
1459+
return {
1460+
account: accountUuid,
1461+
name: 'System',
1462+
personalWorkspace: core.workspace.Any,
1463+
workspaces: {},
1464+
socialIds: []
1465+
}
1466+
}
1467+
14571468
const personalWorkspace = await getPersonalWorkspace(db, account)
14581469

14591470
const userWorkspaces = (await db.getAccountWorkspaces(accountUuid)).filter((it) => isActiveMode(it.status.mode))

server/backup/src/backup.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ export async function backupSize (storage: BackupStorage): Promise<void> {
16451645
/**
16461646
* @public
16471647
*/
1648-
export async function backupDownload (storage: BackupStorage, storeIn: string): Promise<void> {
1648+
export async function backupDownload (storage: BackupStorage, storeIn: string, skipDomains: Set<string>): Promise<void> {
16491649
const infoFile = 'backup.json.gz'
16501650
const sizeFile = 'backup.size.gz'
16511651

@@ -1655,15 +1655,16 @@ export async function backupDownload (storage: BackupStorage, storeIn: string):
16551655
let size = 0
16561656

16571657
const backupInfo: BackupInfo = JSON.parse(gunzipSync(new Uint8Array(await storage.loadFile(infoFile))).toString())
1658-
console.log('workspace:', backupInfo.workspace ?? '', backupInfo.version)
1658+
console.log('Downloading workspace:', backupInfo.workspace ?? '', backupInfo.version, backupInfo.snapshots.length)
16591659

16601660
let sizeInfo: Record<string, number> = {}
16611661
if (await storage.exists(sizeFile)) {
1662+
console.log('Parse size file')
16621663
sizeInfo = JSON.parse(gunzipSync(new Uint8Array(await storage.loadFile(sizeFile))).toString())
16631664
}
1664-
console.log('workspace:', backupInfo.workspace ?? '', backupInfo.version)
16651665

1666-
const addFileSize = async (file: string | undefined | null, force: boolean = false): Promise<void> => {
1666+
const downloadFile = async (file: string | undefined | null, force: boolean = false): Promise<void> => {
1667+
console.log('Download file', file)
16671668
if (file != null) {
16681669
const target = join(storeIn, file)
16691670
const dir = dirname(target)
@@ -1700,17 +1701,21 @@ export async function backupDownload (storage: BackupStorage, storeIn: string):
17001701

17011702
// Let's calculate data size for backup
17021703
for (const sn of backupInfo.snapshots) {
1703-
for (const [, d] of Object.entries(sn.domains)) {
1704-
await addFileSize(d.snapshot)
1704+
console.log('processing', sn.date)
1705+
for (const [k, d] of Object.entries(sn.domains)) {
1706+
if (skipDomains.has(k)) {
1707+
continue
1708+
}
1709+
await downloadFile(d.snapshot)
17051710
for (const snp of d.snapshots ?? []) {
1706-
await addFileSize(snp)
1711+
await downloadFile(snp)
17071712
}
17081713
for (const snp of d.storage ?? []) {
1709-
await addFileSize(snp)
1714+
await downloadFile(snp)
17101715
}
17111716
}
17121717
}
1713-
await addFileSize(infoFile, true)
1718+
await downloadFile(infoFile, true)
17141719

17151720
console.log('Backup size', size / (1024 * 1024), 'Mb')
17161721
}

server/server/src/sessionManager.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,15 @@ export class TSessionManager implements SessionManager {
519519
let account: LoginInfoWithWorkspaces | undefined
520520

521521
try {
522-
account = await this.getLoginWithWorkspaceInfo(rawToken)
522+
account = (token.account === systemAccountUuid)
523+
? {
524+
account: token.account,
525+
name: 'System',
526+
personalWorkspace: core.workspace.Any,
527+
workspaces: {},
528+
socialIds: []
529+
}
530+
: await this.getLoginWithWorkspaceInfo(rawToken)
523531
} catch (err: any) {
524532
ctx.error('failed to get login info', { err })
525533
}
@@ -541,6 +549,10 @@ export class TSessionManager implements SessionManager {
541549
}
542550

543551
let targetInfo = account.workspaces[token.workspace]
552+
let targetWorkspace: WorkspaceUuid | undefined
553+
if (targetInfo !== undefined) {
554+
targetWorkspace = token.workspace
555+
}
544556

545557
if (targetInfo === undefined && token.workspace != null && token.workspace !== '') {
546558
// In case of guest or system account
@@ -567,7 +579,9 @@ export class TSessionManager implements SessionManager {
567579
(ctx.parent ?? ctx).newChild('🧲 session', {}),
568580
token,
569581
ws,
570-
new Set(Object.keys(account.workspaces) as WorkspaceUuid[]),
582+
targetInfo !== undefined && targetWorkspace !== undefined
583+
? new Set([targetWorkspace])
584+
: new Set(Object.keys(account.workspaces) as WorkspaceUuid[]),
571585
accountRef,
572586
account,
573587
token.extra?.mode === 'backup'
@@ -599,10 +613,10 @@ export class TSessionManager implements SessionManager {
599613
// Ignore
600614
})
601615
}
616+
await workspace.addSession(session)
602617
if (open !== undefined) {
603618
await open
604619
}
605-
await workspace.addSession(session)
606620

607621
if (accountUuid !== systemAccountUuid && accountUuid !== guestAccount) {
608622
await this.usersProducer.send(workspace.wsId.uuid, [
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import core, { generateId, Hierarchy, MeasureMetricsContext, ModelDb, platformNow } from '@hcengineering/core'
2+
import contact, { AvatarType, type Contact } from '@hcengineering/contact'
3+
import { faker } from '@faker-js/faker'
4+
import buildModel from '@hcengineering/model-all'
5+
6+
const model = buildModel().getTxes()
7+
describe('mem-objects', () => {
8+
it('check add session', async () => {
9+
const hierarchy = new Hierarchy()
10+
for (const tx of model) {
11+
hierarchy.tx(tx)
12+
}
13+
const memdb = new ModelDb(hierarchy)
14+
memdb.addTxes(new MeasureMetricsContext('test', {}), model, false)
15+
16+
const before = process.memoryUsage().heapUsed
17+
for (let i = 0; i < 100000; i++) {
18+
const d: Contact = {
19+
_class: contact.class.Contact,
20+
_id: generateId(),
21+
_uuid: core.workspace.Any,
22+
space: core.space.Model,
23+
modifiedBy: core.account.System,
24+
modifiedOn: Date.now(),
25+
name: faker.person.fullName(),
26+
avatarType: AvatarType.GRAVATAR,
27+
avatarProps: {
28+
url: faker.internet.username()
29+
}
30+
}
31+
memdb.addDoc(d)
32+
}
33+
const after = process.memoryUsage().heapUsed
34+
console.log('memdb size', after - before)
35+
36+
const t0 = platformNow()
37+
const t1 = await memdb.findAll(contact.class.Contact, {
38+
name: faker.person.fullName()
39+
})
40+
console.log('findAll', platformNow() - t0, t1.length)
41+
})
42+
})

0 commit comments

Comments
 (0)