Skip to content

Commit

Permalink
UBERF-7690: Performance fixes
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 15, 2024
1 parent 7a18f73 commit f9de52f
Show file tree
Hide file tree
Showing 31 changed files with 200 additions and 103 deletions.
2 changes: 1 addition & 1 deletion desktop/src/ui/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async function hydrateNotificationAsYouCan (lastNotification: InboxNotification)
body: ''
}

const account = await client.findOne(contact.class.PersonAccount, { _id: lastNotification.modifiedBy as Ref<PersonAccount> })
const account = await client.getModel().findOne(contact.class.PersonAccount, { _id: lastNotification.modifiedBy as Ref<PersonAccount> })

if (account == null) {
return noPersonData
Expand Down
1 change: 0 additions & 1 deletion models/activity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
3 changes: 2 additions & 1 deletion models/attachment/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ export function createModel (builder: Builder): void {
{ modifiedBy: 1 },
{ createdBy: 1 },
{ createdOn: -1 },
{ state: 1 }
{ state: 1 },
{ _class: 1 }
]
})
}
Expand Down
10 changes: 9 additions & 1 deletion models/bitrix/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
]
})
}
9 changes: 9 additions & 0 deletions models/contact/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Person>
}

Expand Down Expand Up @@ -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 }]
})

Expand Down
20 changes: 18 additions & 2 deletions models/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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,
Expand All @@ -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, {
Expand Down
19 changes: 10 additions & 9 deletions models/core/src/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion models/gmail/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ export function createModel (builder: Builder): void {
{ modifiedBy: 1 },
{ createdBy: 1 },
{ attachedToClass: 1 },
{ createdOn: -1 }
{ createdOn: -1 },
{ modifiedOn: 1 }
]
})

Expand Down
8 changes: 4 additions & 4 deletions models/notification/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -201,7 +201,6 @@ export class TDocNotifyContext extends TDoc implements DocNotifyContext {
objectId!: Ref<Doc>

@Prop(TypeRef(core.class.Class), core.string.Class)
@Index(IndexKind.Indexed)
objectClass!: Ref<Class<Doc>>

@Prop(TypeRef(core.class.Space), core.string.Space)
Expand Down Expand Up @@ -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 }]
})

Expand All @@ -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, {
Expand Down
6 changes: 3 additions & 3 deletions models/recruit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ export function createModel (builder: Builder): void {
sortable: true
},
baseQuery: {
isDone: { $ne: true },
isDone: false,
'$lookup.space.archived': false
}
},
Expand All @@ -500,7 +500,7 @@ export function createModel (builder: Builder): void {
}
},
baseQuery: {
isDone: { $ne: true },
isDone: false,
'$lookup.space.archived': false
}
},
Expand Down Expand Up @@ -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: {
Expand Down
10 changes: 10 additions & 0 deletions models/recruit/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ export const recruitOperation: MigrateOperation = {
func: async (client: MigrationClient) => {
await migrateSpace(client, 'recruit:space:Reviews' as Ref<Space>, 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 }
)
}
}
])
},
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import { getEmbeddedLabel, IntlString } from '@hcengineering/platform'
import { deepEqual } from 'fast-equals'
import { DOMAIN_BENCHMARK } from './benchmark'
import {
Account,
AccountRole,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -604,9 +604,10 @@ export const isEnum =
export async function checkPermission (
client: TxOperations,
_id: Ref<Permission>,
_space: Ref<TypedSpace>
_space: Ref<TypedSpace>,
space?: TypedSpace
): Promise<boolean> {
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 } } })
Expand Down
13 changes: 5 additions & 8 deletions plugins/contact-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand All @@ -331,13 +331,10 @@ function fillStores (): void {

const persons = res.map((it) => it.person)

accountPersonQuery.query<Person>(
contact.class.Person,
{ _id: { $in: persons }, [contact.mixin.Employee]: { $exists: false } },
(res) => {
personAccountPersonByIdStore.set(toIdMap(res))
}
)
accountPersonQuery.query<Person>(contact.class.Person, { _id: { $in: persons } }, (res) => {
const personIn = toIdMap(res)
personAccountPersonByIdStore.set(personIn)
})
})

const providerQuery = createQuery(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
)

Expand Down
18 changes: 10 additions & 8 deletions plugins/tracker-resources/src/components/issues/Issues.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
-->
<script lang="ts">
import { DocumentQuery, Ref } from '@hcengineering/core'
import type { IntlString, Asset } from '@hcengineering/platform'
import type { Asset, IntlString } from '@hcengineering/platform'
import { createQuery } from '@hcengineering/presentation'
import { Issue, IssueStatus, Project } from '@hcengineering/tracker'
import { IModeSelector, resolvedLocationStore } from '@hcengineering/ui'
Expand All @@ -41,18 +41,20 @@
let query: DocumentQuery<Issue> | undefined = undefined
let modeSelectorProps: IModeSelector | undefined = undefined
const archivedProjectQuery = createQuery()
let archived: Ref<Project>[] = []
const allProjectQuery = createQuery()
let allProjects: Pick<Project, '_id' | '_class' | 'archived'>[] = []
archivedProjectQuery.query(
allProjectQuery.query(
tracker.class.Project,
{ archived: true },
{},
(res) => {
archived = res.map((it) => it._id)
allProjects = res
},
{ projection: { _id: 1 } }
{ projection: { _id: 1, archived: 1 } }
)
$: spaceQuery = currentSpace ? { space: currentSpace } : { space: { $nin: archived } }
$: spaceQuery = currentSpace
? { space: currentSpace }
: { space: { $in: allProjects.filter((it) => !it.archived).map((it) => it._id) } }
$: all = { ...baseQuery, ...spaceQuery }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@
{ sort: { _id: 1 }, projection: { _id: 1 } }
)
const archivedProjectQuery = createQuery()
let archived: Ref<Project>[] = []
const allProjectQuery = createQuery()
let allProjects: Pick<Project, '_class' | '_id' | 'archived'>[] = []
archivedProjectQuery.query(
allProjectQuery.query(
tracker.class.Project,
{ archived: true },
{},
(res) => {
archived = res.map((it) => it._id)
allProjects = res
},
{ projection: { _id: 1 } }
{ projection: { _id: 1, archived: 1 } }
)
$: queries = { assigned, active, backlog, created, subscribed }
Expand All @@ -95,7 +95,7 @@
$: if (mode !== undefined) {
query = { ...(queries as any)[mode] }
if (query?.space === undefined) {
query = { ...query, space: { $nin: archived } }
query = { ...query, space: { $in: allProjects.filter((it) => !it.archived).map((it) => it._id) } }
}
modeSelectorProps = {
config,
Expand Down
Loading

0 comments on commit f9de52f

Please sign in to comment.