Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBERF-6469: Fix slow index creation #5324

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 54 additions & 55 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions dev/client-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//

import clientPlugin from '@hcengineering/client'
import { AccountClient, createClient } from '@hcengineering/core'
import core, { AccountClient, createClient, groupByArray, MigrationState } from '@hcengineering/core'
import { migrateOperations } from '@hcengineering/model-all'
import { getMetadata, getResource } from '@hcengineering/platform'
import { connect } from './connection'
Expand All @@ -27,9 +27,18 @@ export default async () => {
GetClient: async (): Promise<AccountClient> => {
if (client === undefined) {
client = await createClient(connect)

const states = await client.findAll<MigrationState>(core.class.MigrationState, {})
const migrateState = new Map(
Array.from(groupByArray(states, (it) => it.plugin).entries()).map((it) => [
it[0],
new Set(it[1].map((q) => q.state))
])
)
;(client as any).migrateState = migrateState
for (const op of migrateOperations) {
console.log('Migrate', op[0])
await op[1].upgrade(client, {
await op[1].upgrade(client as any, {
log (msg, data) {
console.log(msg, data)
},
Expand Down
2 changes: 1 addition & 1 deletion dev/tool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"commander": "^8.1.0",
"csv-parse": "~5.1.0",
"email-addresses": "^5.0.0",
"fast-equals": "^2.0.3",
"fast-equals": "^5.0.1",
"got": "^11.8.3",
"libphonenumber-js": "^1.9.46",
"mime-types": "~2.1.34",
Expand Down
16 changes: 8 additions & 8 deletions dev/tool/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export function devTool (
const _client = await client.getClient()
await f(_client.db(ACCOUNT_DB), _client)
client.close()
console.log(`closing database connection to '${uri}'...`)
}

program.version('0.0.1')
Expand Down Expand Up @@ -363,13 +364,12 @@ export function devTool (

const avgTime = (Date.now() - st) / (workspaces.length - toProcess + 1)
console.log(
'---UPGRADING----',
ws.workspace,
ws.workspaceUrl,
'----------------------------------------------------------\n---UPGRADING----',
'pending: ',
toProcess,
'ETA:',
Math.floor(avgTime * toProcess * 100) / 100
'ETA: ',
Math.floor(avgTime * toProcess),
ws.workspace
)
toProcess--
try {
Expand All @@ -384,11 +384,11 @@ export function devTool (
logger,
cmd.force
)
console.log('---UPGRADING-DONE----', ws.workspace, Date.now() - t)
console.log('---done---------', 'pending: ', toProcess, 'TIME:', Date.now() - t, ws.workspace)
} catch (err: any) {
withError.push(ws.workspace)
logger.log('error', JSON.stringify(err))
console.log('---UPGRADING-FAILED----', ws.workspace, Date.now() - t)
console.log(' FAILED-------', 'pending: ', toProcess, 'TIME:', Date.now() - t, ws.workspace)
} finally {
if (!cmd.console) {
;(logger as FileModelLogger).close()
Expand All @@ -409,7 +409,7 @@ export function devTool (
console.log('Upgrade done')
// console.log((process as any)._getActiveHandles())
// console.log((process as any)._getActiveRequests())
process.exit()
// process.exit()
} else {
console.log('UPGRADE write logs at:', cmd.logs)
for (const ws of workspaces) {
Expand Down
28 changes: 22 additions & 6 deletions models/activity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class TActivityMessage extends TAttachedDoc implements ActivityMessage {
repliedPersons?: Ref<Person>[]

@Prop(TypeTimestamp(), activity.string.LastReply)
@Index(IndexKind.Indexed)
// @Index(IndexKind.Indexed)
lastReply?: Timestamp

@Prop(Collection(activity.class.Reaction), activity.string.Reactions)
Expand All @@ -134,15 +134,15 @@ export class TDocUpdateMessage extends TActivityMessage implements DocUpdateMess
objectId!: Ref<Doc>

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

@Prop(TypeRef(core.class.TxCUD), core.string.Object)
@Index(IndexKind.Indexed)
// @Index(IndexKind.Indexed)
txId!: Ref<TxCUD<Doc>>

@Prop(TypeString(), core.string.Object)
@Index(IndexKind.Indexed)
// @Index(IndexKind.Indexed)
action!: DocUpdateAction

updateCollection?: string
Expand All @@ -153,11 +153,11 @@ export class TDocUpdateMessage extends TActivityMessage implements DocUpdateMess
export class TActivityReference extends TActivityMessage implements ActivityReference {
// Source document we have reference from, it should be parent document for Comment/Message.
@Prop(TypeRef(core.class.Doc), core.string.Object)
@Index(IndexKind.Indexed)
// @Index(IndexKind.Indexed)
srcDocId!: Ref<Doc>

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

// Reference to comment/message in source doc
Expand Down Expand Up @@ -386,6 +386,22 @@ export function createModel (builder: Builder): void {
},
activity.ids.AddReactionNotification
)

builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, {
domain: DOMAIN_ACTIVITY,
indexes: [
{ attachedTo: 1, createdOn: 1 },
{ attachedTo: 1, createdOn: -1 }
],
disabled: [
{ modifiedOn: 1 },
{ createdOn: -1 },
{ space: 1 },
{ modifiedBy: 1 },
{ createdBy: 1 },
{ attachedToClass: 1 }
]
})
}

export default activity
11 changes: 11 additions & 0 deletions models/attachment/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,17 @@ export function createModel (builder: Builder): void {
group: 'edit'
}
})
builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, {
domain: DOMAIN_ATTACHMENT,
disabled: [
{ attachedToClass: 1 },
{ modifiedOn: 1 },
{ modifiedBy: 1 },
{ createdBy: 1 },
{ createdOn: -1 },
{ state: 1 }
]
})
}

export default attachment
4 changes: 4 additions & 0 deletions models/bitrix/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,8 @@ export function createModel (builder: Builder): void {
},
bitrix.action.BitrixImport
)
builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, {
domain: DOMAIN_BITRIX,
disabled: [{ _id: 1 }, { _class: 1 }, { space: 1 }, { modifiedBy: 1 }, { createdBy: 1 }, { createdOn: -1 }]
})
}
19 changes: 16 additions & 3 deletions models/bitrix/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@
//

import core, { TxOperations } from '@hcengineering/core'
import { type MigrateOperation, type MigrationClient, type MigrationUpgradeClient } from '@hcengineering/model'
import {
tryUpgrade,
type MigrateOperation,
type MigrationClient,
type MigrationUpgradeClient
} from '@hcengineering/model'
import bitrix from './plugin'
import { bitrixId } from '@hcengineering/bitrix'

async function createSpace (tx: TxOperations): Promise<void> {
const current = await tx.findOne(core.class.Space, {
Expand All @@ -40,7 +46,14 @@ async function createSpace (tx: TxOperations): Promise<void> {
export const bitrixOperation: MigrateOperation = {
async migrate (client: MigrationClient): Promise<void> {},
async upgrade (client: MigrationUpgradeClient): Promise<void> {
const tx = new TxOperations(client, core.account.System)
await createSpace(tx)
await tryUpgrade(client, bitrixId, [
{
state: 'create-defaults',
func: async (client) => {
const tx = new TxOperations(client, core.account.System)
await createSpace(tx)
}
}
])
}
}
14 changes: 11 additions & 3 deletions models/board/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
type MigrationClient,
type MigrationUpgradeClient,
createOrUpdate,
tryMigrate
tryMigrate,
tryUpgrade
} from '@hcengineering/model'
import core, { DOMAIN_SPACE } from '@hcengineering/model-core'
import { DOMAIN_TASK, createProjectType, createSequence, fixTaskTypes } from '@hcengineering/model-task'
Expand Down Expand Up @@ -184,7 +185,14 @@ export const boardOperation: MigrateOperation = {
])
},
async upgrade (client: MigrationUpgradeClient): Promise<void> {
const ops = new TxOperations(client, core.account.System)
await createDefaults(ops)
await tryUpgrade(client, boardId, [
{
state: 'board0001',
func: async (client) => {
const ops = new TxOperations(client, core.account.System)
await createDefaults(ops)
}
}
])
}
}
12 changes: 12 additions & 0 deletions models/calendar/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,18 @@ export function createModel (builder: Builder): void {
builder.mixin(calendar.class.Event, core.class.Class, view.mixin.ObjectPresenter, {
presenter: calendar.component.EventPresenter
})

builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, {
domain: DOMAIN_CALENDAR,
disabled: [
{ attachedToClass: 1 },
{ modifiedOn: 1 },
{ modifiedBy: 1 },
{ createdBy: 1 },
{ createdOn: -1 },
{ state: 1 }
]
})
}

export default calendar
27 changes: 20 additions & 7 deletions models/calendar/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import contact from '@hcengineering/contact'
import core, { TxOperations, type Ref } from '@hcengineering/core'
import {
tryMigrate,
tryUpgrade,
type MigrateOperation,
type MigrationClient,
type MigrationUpgradeClient
Expand Down Expand Up @@ -139,20 +140,32 @@ async function migrateTimezone (client: MigrationClient): Promise<void> {

export const calendarOperation: MigrateOperation = {
async migrate (client: MigrationClient): Promise<void> {
await fixEventDueDate(client)
await migrateReminders(client)
await fillOriginalStartTime(client)
await migrateSync(client)
await migrateExternalCalendars(client)
await tryMigrate(client, calendarId, [
{
state: 'calendar001',
func: async (client) => {
await fixEventDueDate(client)
await migrateReminders(client)
await fillOriginalStartTime(client)
await migrateSync(client)
await migrateExternalCalendars(client)
}
},
{
state: 'timezone',
func: migrateTimezone
}
])
},
async upgrade (client: MigrationUpgradeClient): Promise<void> {
const tx = new TxOperations(client, core.account.System)
await migrateCalendars(tx)
await tryUpgrade(client, calendarId, [
{
state: 'u-calendar0002',
func: async (client) => {
const tx = new TxOperations(client, core.account.System)
await migrateCalendars(tx)
}
}
])
}
}
5 changes: 5 additions & 0 deletions models/chunter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,11 @@ export function createModel (builder: Builder, options = { addApplication: true
builder.mixin(chunter.class.ThreadMessage, core.class.Class, activity.mixin.ActivityMessagePreview, {
presenter: chunter.component.ThreadMessagePreview
})

builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, {
domain: DOMAIN_CHUNTER,
disabled: [{ _class: 1 }, { space: 1 }, { modifiedBy: 1 }, { createdBy: 1 }, { createdOn: -1 }]
})
}

export default chunter
22 changes: 14 additions & 8 deletions models/chunter/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import {
type MigrateOperation,
type MigrationClient,
type MigrationUpgradeClient,
tryMigrate
tryMigrate,
tryUpgrade
} from '@hcengineering/model'
import activity, { DOMAIN_ACTIVITY } from '@hcengineering/model-activity'
import notification from '@hcengineering/notification'

import chunter from './plugin'

const DOMAIN_COMMENT = 'comment' as Domain
export const DOMAIN_COMMENT = 'comment' as Domain

export async function createDocNotifyContexts (
client: MigrationUpgradeClient,
Expand Down Expand Up @@ -128,18 +129,23 @@ export const chunterOperation: MigrateOperation = {
{
state: 'create-chat-messages',
func: convertCommentsToChatMessages
}
])
await tryMigrate(client, chunterId, [
},
{
state: 'remove-backlinks',
func: removeBacklinks
}
])
},
async upgrade (client: MigrationUpgradeClient): Promise<void> {
const tx = new TxOperations(client, core.account.System)
await createGeneral(client, tx)
await createRandom(client, tx)
await tryUpgrade(client, chunterId, [
{
state: 'create-defaults',
func: async (client) => {
const tx = new TxOperations(client, core.account.System)
await createGeneral(client, tx)
await createRandom(client, tx)
}
}
])
}
}
18 changes: 18 additions & 0 deletions models/contact/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,4 +1133,22 @@ export function createModel (builder: Builder): void {
)

createPublicLinkAction(builder, contact.class.Contact, contact.action.PublicLink)

builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, {
domain: DOMAIN_CHANNEL,
disabled: [
{ attachedToClass: 1 },
{ provider: 1 },
{ space: 1 },
{ modifiedBy: 1 },
{ modifiedOn: 1 },
{ createdBy: 1 },
{ createdBy: -1 },
{ createdOn: -1 }
]
})
builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, {
domain: DOMAIN_CONTACT,
disabled: [{ attachedToClass: 1 }, { modifiedBy: 1 }, { createdBy: 1 }, { createdOn: -1 }, { attachedTo: 1 }]
})
}
Loading