mirror of
https://github.com/hcengineering/platform.git
synced 2025-03-21 23:08:41 +00:00
Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
22c6f1f49b
@ -283,10 +283,12 @@ export function createModel (builder: Builder): void {
|
|||||||
|
|
||||||
builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, {
|
builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, {
|
||||||
domain: DOMAIN_DOC_INDEX_STATE,
|
domain: DOMAIN_DOC_INDEX_STATE,
|
||||||
indexes: [{ keys: { removed: 1 }, filter: { removed: true } }],
|
indexes: [
|
||||||
|
{ keys: { removed: 1 }, filter: { removed: true } },
|
||||||
|
{ keys: { _class: 1 }, filter: { _class: core.class.DocIndexState } }
|
||||||
|
],
|
||||||
disabled: [
|
disabled: [
|
||||||
{ attachedToClass: 1 },
|
{ attachedToClass: 1 },
|
||||||
{ objectClass: 1 },
|
|
||||||
{ stages: 1 },
|
{ stages: 1 },
|
||||||
{ generationId: 1 },
|
{ generationId: 1 },
|
||||||
{ space: 1 },
|
{ space: 1 },
|
||||||
|
@ -93,7 +93,7 @@ export async function loadIndexStageStage (
|
|||||||
newValue: any
|
newValue: any
|
||||||
): Promise<[boolean | string, IndexStageState]> {
|
): Promise<[boolean | string, IndexStageState]> {
|
||||||
if (state === undefined) {
|
if (state === undefined) {
|
||||||
;[state] = await storage.findAll(ctx, core.class.IndexStageState, { stageId })
|
;[state] = await storage.findAll(ctx, core.class.IndexStageState, { stageId }, { limit: 1 })
|
||||||
}
|
}
|
||||||
const attributes: Record<string, any> = state?.attributes ?? {}
|
const attributes: Record<string, any> = state?.attributes ?? {}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ export class DomainIndexHelperImpl implements DomainHelper {
|
|||||||
const allIndexes = (await operations.listIndexes(domain)).filter((it) => it.name !== '_id_')
|
const allIndexes = (await operations.listIndexes(domain)).filter((it) => it.name !== '_id_')
|
||||||
ctx.info('check indexes', { domain, has50Documents, documents })
|
ctx.info('check indexes', { domain, has50Documents, documents })
|
||||||
if (has50Documents) {
|
if (has50Documents) {
|
||||||
for (const vv of [...(domainInfo?.values() ?? []), ...(cfg?.indexes ?? [])]) {
|
async function checkIndex (vv: string | FieldIndexConfig<Doc>, checkDisabled: boolean): Promise<void> {
|
||||||
try {
|
try {
|
||||||
let name: string
|
let name: string
|
||||||
if (typeof vv === 'string') {
|
if (typeof vv === 'string') {
|
||||||
@ -111,19 +111,23 @@ export class DomainIndexHelperImpl implements DomainHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if index is disabled or not
|
// Check if index is disabled or not
|
||||||
const isDisabled =
|
let isDisabled =
|
||||||
cfg?.disabled?.some((it) => {
|
cfg?.disabled?.some((it) => {
|
||||||
const _it = typeof it === 'string' ? { [it]: 1 } : it
|
const _it = typeof it === 'string' ? { [it]: 1 } : it
|
||||||
const _vv = typeof vv === 'string' ? { [vv]: 1 } : vv.keys
|
const _vv = typeof vv === 'string' ? { [vv]: 1 } : vv.keys
|
||||||
return deepEqual(_it, _vv)
|
return deepEqual(_it, _vv)
|
||||||
}) ?? false
|
}) ?? false
|
||||||
|
|
||||||
|
if (!checkDisabled) {
|
||||||
|
isDisabled = false
|
||||||
|
}
|
||||||
if (isDisabled) {
|
if (isDisabled) {
|
||||||
// skip index since it is disabled
|
// skip index since it is disabled
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if (added.has(name)) {
|
if (added.has(name)) {
|
||||||
// Index already added
|
// Index already added
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
added.add(name)
|
added.add(name)
|
||||||
|
|
||||||
@ -133,20 +137,25 @@ export class DomainIndexHelperImpl implements DomainHelper {
|
|||||||
}
|
}
|
||||||
const exists = existingOne !== -1
|
const exists = existingOne !== -1
|
||||||
// Check if index exists
|
// Check if index exists
|
||||||
if (!exists) {
|
if (!exists && !isDisabled) {
|
||||||
if (!isDisabled) {
|
// Check if not disabled
|
||||||
// Check if not disabled
|
bb.push(vv)
|
||||||
bb.push(vv)
|
await operations.createIndex(domain, vv, {
|
||||||
await operations.createIndex(domain, vv, {
|
name
|
||||||
name
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
Analytics.handleError(err)
|
Analytics.handleError(err)
|
||||||
ctx.error('error: failed to create index', { domain, vv, err })
|
ctx.error('error: failed to create index', { domain, vv, err })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const vv of [...(domainInfo?.values() ?? [])]) {
|
||||||
|
await checkIndex(vv, true)
|
||||||
|
}
|
||||||
|
for (const vv of [...(cfg?.indexes ?? [])]) {
|
||||||
|
await checkIndex(vv, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (allIndexes.length > 0) {
|
if (allIndexes.length > 0) {
|
||||||
for (const c of allIndexes) {
|
for (const c of allIndexes) {
|
||||||
|
@ -385,7 +385,7 @@ export async function upgradeModel (
|
|||||||
|
|
||||||
await tryMigrate(migrateClient, coreId, [
|
await tryMigrate(migrateClient, coreId, [
|
||||||
{
|
{
|
||||||
state: 'sparse',
|
state: 'indexes-v2',
|
||||||
func: upgradeIndexes
|
func: upgradeIndexes
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
Loading…
Reference in New Issue
Block a user