From b0d8b62e82e55b31bc2971e0b052372bd34ca57a Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Thu, 15 Aug 2024 15:50:20 +0700 Subject: [PATCH] UBERF-7690: Performance fixes Signed-off-by: Andrey Sobolev --- desktop/src/ui/notifications.ts | 2 +- models/activity/src/index.ts | 1 - models/attachment/src/index.ts | 3 +- models/bitrix/src/index.ts | 10 +++++- models/contact/src/index.ts | 9 +++++ models/core/src/index.ts | 20 +++++++++-- models/core/src/security.ts | 19 +++++----- models/gmail/src/index.ts | 3 +- models/notification/src/index.ts | 8 ++--- models/recruit/src/index.ts | 6 ++-- models/recruit/src/migration.ts | 10 ++++++ packages/core/src/utils.ts | 7 ++-- plugins/calendar/src/index.ts | 2 +- plugins/contact-resources/src/utils.ts | 13 +++---- .../src/inboxNotificationsClient.ts | 6 +--- .../src/components/issues/Issues.svelte | 18 +++++----- .../src/components/myissues/MyIssues.svelte | 14 ++++---- plugins/view-resources/src/utils.ts | 8 +++++ .../view-resources/src/visibilityTester.ts | 35 +++++++++++++------ .../src/components/Navigator.svelte | 8 +++-- pods/server/Dockerfile | 2 +- server-plugins/recruit-resources/src/index.ts | 18 +++++----- server-plugins/setting-resources/src/index.ts | 8 ++--- server-plugins/tracker-resources/src/index.ts | 14 ++++---- server/core/src/server/domainHelper.ts | 4 +++ server/mongo/src/storage.ts | 14 +++++++- server/mongo/src/utils.ts | 18 ++++++++-- server/tool/src/index.ts | 2 +- server/uws/uws.sh | 6 ++-- server/ws/.gitignore | 2 +- server/ws/src/server_http.ts | 9 ++--- .../server-github-resources/src/index.ts | 4 +-- 32 files changed, 200 insertions(+), 103 deletions(-) diff --git a/desktop/src/ui/notifications.ts b/desktop/src/ui/notifications.ts index 7b37aa8e82..ff8e178eac 100644 --- a/desktop/src/ui/notifications.ts +++ b/desktop/src/ui/notifications.ts @@ -67,7 +67,7 @@ async function hydrateNotificationAsYouCan (lastNotification: InboxNotification) body: '' } - const account = await client.findOne(contact.class.PersonAccount, { _id: lastNotification.modifiedBy as Ref }) + const account = await client.getModel().findOne(contact.class.PersonAccount, { _id: lastNotification.modifiedBy as Ref }) if (account == null) { return noPersonData diff --git a/models/activity/src/index.ts b/models/activity/src/index.ts index 5e1e3f1192..83b979d3bb 100644 --- a/models/activity/src/index.ts +++ b/models/activity/src/index.ts @@ -362,7 +362,6 @@ export function createModel (builder: Builder): void { builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, { domain: DOMAIN_ACTIVITY, - indexes: [{ keys: { attachedTo: 1, createdOn: 1 } }, { keys: { attachedTo: 1, createdOn: -1 } }], disabled: [ { modifiedOn: 1 }, { createdOn: -1 }, diff --git a/models/attachment/src/index.ts b/models/attachment/src/index.ts index 46a400417b..fa062aeb06 100644 --- a/models/attachment/src/index.ts +++ b/models/attachment/src/index.ts @@ -199,7 +199,8 @@ export function createModel (builder: Builder): void { { modifiedBy: 1 }, { createdBy: 1 }, { createdOn: -1 }, - { state: 1 } + { state: 1 }, + { _class: 1 } ] }) } diff --git a/models/bitrix/src/index.ts b/models/bitrix/src/index.ts index 191ff9df9b..28f3bcaaaf 100644 --- a/models/bitrix/src/index.ts +++ b/models/bitrix/src/index.ts @@ -135,6 +135,14 @@ export function createModel (builder: Builder): void { ) builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, { domain: DOMAIN_BITRIX, - disabled: [{ _id: 1 }, { _class: 1 }, { space: 1 }, { modifiedBy: 1 }, { createdBy: 1 }, { createdOn: -1 }] + disabled: [ + { _id: 1 }, + { _class: 1 }, + { space: 1 }, + { modifiedBy: 1 }, + { createdBy: 1 }, + { createdOn: -1 }, + { modifiedOn: 1 } + ] }) } diff --git a/models/contact/src/index.ts b/models/contact/src/index.ts index d92da09886..d3dcacdc10 100644 --- a/models/contact/src/index.ts +++ b/models/contact/src/index.ts @@ -223,6 +223,7 @@ export class TContactsTab extends TDoc implements ContactsTab { @Model(contact.class.PersonSpace, core.class.Space) export class TPersonSpace extends TSpace implements PersonSpace { @Prop(TypeRef(contact.class.Person), contact.string.Person) + @Index(IndexKind.Indexed) person!: Ref } @@ -1170,6 +1171,14 @@ export function createModel (builder: Builder): void { }) builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, { domain: DOMAIN_CONTACT, + indexes: [ + { + keys: { + _class: 1, + [contact.mixin.Employee + '.active']: 1 + } + } + ], disabled: [{ attachedToClass: 1 }, { modifiedBy: 1 }, { createdBy: 1 }, { createdOn: -1 }, { attachedTo: 1 }] }) diff --git a/models/core/src/index.ts b/models/core/src/index.ts index b37e77d1ac..adf3af9eaf 100644 --- a/models/core/src/index.ts +++ b/models/core/src/index.ts @@ -197,6 +197,7 @@ export function createModel (builder: Builder): void { builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, { domain: DOMAIN_TX, disabled: [ + { _class: 1 }, { space: 1 }, { objectClass: 1 }, { createdBy: 1 }, @@ -267,7 +268,14 @@ export function createModel (builder: Builder): void { builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, { domain: DOMAIN_STATUS, - disabled: [{ modifiedOn: 1 }, { modifiedBy: 1 }, { createdBy: 1 }, { createdBy: -1 }, { createdOn: -1 }] + disabled: [ + { modifiedOn: 1 }, + { modifiedBy: 1 }, + { createdBy: 1 }, + { createdBy: -1 }, + { createdOn: -1 }, + { space: 1 } + ] }) builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, { domain: DOMAIN_SPACE, @@ -276,7 +284,15 @@ export function createModel (builder: Builder): void { builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, { domain: DOMAIN_BLOB, - disabled: [{ _class: 1 }, { space: 1 }, { modifiedBy: 1 }, { createdBy: 1 }, { createdBy: -1 }, { createdOn: -1 }] + disabled: [ + { _class: 1 }, + { space: 1 }, + { modifiedBy: 1 }, + { createdBy: 1 }, + { createdBy: -1 }, + { createdOn: -1 }, + { modifiedOn: 1 } + ] }) builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, { diff --git a/models/core/src/security.ts b/models/core/src/security.ts index fa694867e3..2c038b6bda 100644 --- a/models/core/src/security.ts +++ b/models/core/src/security.ts @@ -14,22 +14,22 @@ // import { + DOMAIN_MODEL, + IndexKind, type Account, type AccountRole, type Arr, + type Class, + type CollectionSize, type Domain, - DOMAIN_MODEL, - IndexKind, + type Permission, type Ref, + type Role, + type RolesAssignment, type Space, - type TypedSpace, type SpaceType, type SpaceTypeDescriptor, - type Role, - type Class, - type Permission, - type CollectionSize, - type RolesAssignment + type TypedSpace } from '@hcengineering/core' import { ArrOf, @@ -46,7 +46,7 @@ import { } from '@hcengineering/model' import { getEmbeddedLabel, type Asset, type IntlString } from '@hcengineering/platform' import core from './component' -import { TDoc, TAttachedDoc } from './core' +import { TAttachedDoc, TDoc } from './core' export const DOMAIN_SPACE = 'space' as Domain @@ -67,6 +67,7 @@ export class TSpace extends TDoc implements Space { private!: boolean @Prop(TypeBoolean(), core.string.Archived) + @Index(IndexKind.Indexed) archived!: boolean @Prop(ArrOf(TypeRef(core.class.Account)), core.string.Members) diff --git a/models/gmail/src/index.ts b/models/gmail/src/index.ts index b325245753..4801861cb4 100644 --- a/models/gmail/src/index.ts +++ b/models/gmail/src/index.ts @@ -254,7 +254,8 @@ export function createModel (builder: Builder): void { { modifiedBy: 1 }, { createdBy: 1 }, { attachedToClass: 1 }, - { createdOn: -1 } + { createdOn: -1 }, + { modifiedOn: 1 } ] }) diff --git a/models/notification/src/index.ts b/models/notification/src/index.ts index aff1814fc6..a4331e44a1 100644 --- a/models/notification/src/index.ts +++ b/models/notification/src/index.ts @@ -16,6 +16,7 @@ import activity, { type ActivityMessage } from '@hcengineering/activity' import chunter from '@hcengineering/chunter' +import { type PersonSpace } from '@hcengineering/contact' import { AccountRole, DOMAIN_MODEL, @@ -49,7 +50,6 @@ import { UX, type Builder } from '@hcengineering/model' -import { type PersonSpace } from '@hcengineering/contact' import core, { TClass, TDoc } from '@hcengineering/model-core' import preference, { TPreference } from '@hcengineering/model-preference' import view, { createAction, template } from '@hcengineering/model-view' @@ -201,7 +201,6 @@ export class TDocNotifyContext extends TDoc implements DocNotifyContext { objectId!: Ref @Prop(TypeRef(core.class.Class), core.string.Class) - @Index(IndexKind.Indexed) objectClass!: Ref> @Prop(TypeRef(core.class.Space), core.string.Space) @@ -632,7 +631,7 @@ export function createModel (builder: Builder): void { builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, { domain: DOMAIN_NOTIFICATION, - indexes: [{ keys: { user: 1, archived: 1 } }], + indexes: [{ keys: { user: 1, archived: 1, space: 1 } }], disabled: [{ modifiedOn: 1 }, { modifiedBy: 1 }, { createdBy: 1 }, { isViewed: 1 }, { hidden: 1 }] }) @@ -647,7 +646,8 @@ export function createModel (builder: Builder): void { { isViewed: 1 }, { hidden: 1 }, { createdOn: -1 }, - { attachedTo: 1 } + { attachedTo: 1 }, + { space: 1 } ] }) builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, { diff --git a/models/recruit/src/index.ts b/models/recruit/src/index.ts index 4fc4ef12f6..dda0c330f2 100644 --- a/models/recruit/src/index.ts +++ b/models/recruit/src/index.ts @@ -480,7 +480,7 @@ export function createModel (builder: Builder): void { sortable: true }, baseQuery: { - isDone: { $ne: true }, + isDone: false, '$lookup.space.archived': false } }, @@ -500,7 +500,7 @@ export function createModel (builder: Builder): void { } }, baseQuery: { - isDone: { $ne: true }, + isDone: false, '$lookup.space.archived': false } }, @@ -796,7 +796,7 @@ export function createModel (builder: Builder): void { descriptor: task.viewlet.Kanban, // eslint-disable-next-line @typescript-eslint/consistent-type-assertions baseQuery: { - isDone: { $ne: true }, + isDone: false, '$lookup.space.archived': false }, viewOptions: { diff --git a/models/recruit/src/migration.ts b/models/recruit/src/migration.ts index 6004bab9b3..05520bd0ee 100644 --- a/models/recruit/src/migration.ts +++ b/models/recruit/src/migration.ts @@ -60,6 +60,16 @@ export const recruitOperation: MigrateOperation = { func: async (client: MigrationClient) => { await migrateSpace(client, 'recruit:space:Reviews' as Ref, core.space.Workspace, [DOMAIN_CALENDAR]) } + }, + { + state: 'migrate-applicants', + func: async (client: MigrationClient) => { + await client.update( + DOMAIN_TASK, + { _class: recruit.class.Applicant, isDone: { $nin: [false, true] } }, + { isDone: false } + ) + } } ]) }, diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index 2fe36d2e10..783515867b 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -15,6 +15,7 @@ import { getEmbeddedLabel, IntlString } from '@hcengineering/platform' import { deepEqual } from 'fast-equals' +import { DOMAIN_BENCHMARK } from './benchmark' import { Account, AccountRole, @@ -46,7 +47,6 @@ import { TxOperations } from './operations' import { isPredicate } from './predicate' import { DocumentQuery, FindResult } from './storage' import { DOMAIN_TX } from './tx' -import { DOMAIN_BENCHMARK } from './benchmark' function toHex (value: number, chars: number): string { const result = value.toString(16) @@ -604,9 +604,10 @@ export const isEnum = export async function checkPermission ( client: TxOperations, _id: Ref, - _space: Ref + _space: Ref, + space?: TypedSpace ): Promise { - const space = await client.findOne(core.class.TypedSpace, { _id: _space }) + space = space ?? (await client.findOne(core.class.TypedSpace, { _id: _space })) const type = await client .getModel() .findOne(core.class.SpaceType, { _id: space?.type }, { lookup: { _id: { roles: core.class.Role } } }) diff --git a/plugins/calendar/src/index.ts b/plugins/calendar/src/index.ts index b2f0f3bc08..dd2023d4ba 100644 --- a/plugins/calendar/src/index.ts +++ b/plugins/calendar/src/index.ts @@ -16,7 +16,7 @@ import type { AttachedDoc, Class, Doc, Markup, Mixin, Ref, SystemSpace, Timestam import { NotificationType } from '@hcengineering/notification' import type { Asset, IntlString, Metadata, Plugin } from '@hcengineering/platform' import { plugin } from '@hcengineering/platform' -import type { Handler, IntegrationType } from '@hcengineering/setting' +import { Handler, IntegrationType } from '@hcengineering/setting' import { AnyComponent, ComponentExtensionId } from '@hcengineering/ui' /** diff --git a/plugins/contact-resources/src/utils.ts b/plugins/contact-resources/src/utils.ts index 50ebebca15..ec788c0f2b 100644 --- a/plugins/contact-resources/src/utils.ts +++ b/plugins/contact-resources/src/utils.ts @@ -320,7 +320,7 @@ function fillStores (): void { const accountPersonQuery = createQuery(true) const query = createQuery(true) - query.query(contact.mixin.Employee, {}, (res) => { + query.query(contact.mixin.Employee, { [contact.mixin.Employee + '.active']: { $in: [true, false] } }, (res) => { employeesStore.set(res) employeeByIdStore.set(toIdMap(res)) }) @@ -331,13 +331,10 @@ function fillStores (): void { const persons = res.map((it) => it.person) - accountPersonQuery.query( - contact.class.Person, - { _id: { $in: persons }, [contact.mixin.Employee]: { $exists: false } }, - (res) => { - personAccountPersonByIdStore.set(toIdMap(res)) - } - ) + accountPersonQuery.query(contact.class.Person, { _id: { $in: persons } }, (res) => { + const personIn = toIdMap(res) + personAccountPersonByIdStore.set(personIn) + }) }) const providerQuery = createQuery(true) diff --git a/plugins/notification-resources/src/inboxNotificationsClient.ts b/plugins/notification-resources/src/inboxNotificationsClient.ts index 206f9b376b..6e7a2b1b7e 100644 --- a/plugins/notification-resources/src/inboxNotificationsClient.ts +++ b/plugins/notification-resources/src/inboxNotificationsClient.ts @@ -112,12 +112,8 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient { user: getCurrentAccount()._id }, (result: InboxNotification[]) => { + result.sort((a, b) => (b.createdOn ?? b.modifiedOn) - (a.createdOn ?? a.modifiedOn)) this.otherInboxNotifications.set(result) - }, - { - sort: { - createdOn: SortingOrder.Descending - } } ) diff --git a/plugins/tracker-resources/src/components/issues/Issues.svelte b/plugins/tracker-resources/src/components/issues/Issues.svelte index c7b7cac57c..a462cecdab 100644 --- a/plugins/tracker-resources/src/components/issues/Issues.svelte +++ b/plugins/tracker-resources/src/components/issues/Issues.svelte @@ -14,7 +14,7 @@ -->