Merge remote-tracking branch 'origin/develop'

This commit is contained in:
Andrey Sobolev 2024-08-05 15:26:26 +07:00
commit 22c6f1f49b
No known key found for this signature in database
GPG Key ID: BD80F68D68D8F7F2
4 changed files with 27 additions and 16 deletions

View File

@ -283,10 +283,12 @@ export function createModel (builder: Builder): void {
builder.createDoc(core.class.DomainIndexConfiguration, core.space.Model, {
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: [
{ attachedToClass: 1 },
{ objectClass: 1 },
{ stages: 1 },
{ generationId: 1 },
{ space: 1 },

View File

@ -93,7 +93,7 @@ export async function loadIndexStageStage (
newValue: any
): Promise<[boolean | string, IndexStageState]> {
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 ?? {}

View File

@ -93,7 +93,7 @@ export class DomainIndexHelperImpl implements DomainHelper {
const allIndexes = (await operations.listIndexes(domain)).filter((it) => it.name !== '_id_')
ctx.info('check indexes', { domain, has50Documents, documents })
if (has50Documents) {
for (const vv of [...(domainInfo?.values() ?? []), ...(cfg?.indexes ?? [])]) {
async function checkIndex (vv: string | FieldIndexConfig<Doc>, checkDisabled: boolean): Promise<void> {
try {
let name: string
if (typeof vv === 'string') {
@ -111,19 +111,23 @@ export class DomainIndexHelperImpl implements DomainHelper {
}
// Check if index is disabled or not
const isDisabled =
let isDisabled =
cfg?.disabled?.some((it) => {
const _it = typeof it === 'string' ? { [it]: 1 } : it
const _vv = typeof vv === 'string' ? { [vv]: 1 } : vv.keys
return deepEqual(_it, _vv)
}) ?? false
if (!checkDisabled) {
isDisabled = false
}
if (isDisabled) {
// skip index since it is disabled
continue
return
}
if (added.has(name)) {
// Index already added
continue
return
}
added.add(name)
@ -133,20 +137,25 @@ export class DomainIndexHelperImpl implements DomainHelper {
}
const exists = existingOne !== -1
// Check if index exists
if (!exists) {
if (!isDisabled) {
// Check if not disabled
bb.push(vv)
await operations.createIndex(domain, vv, {
name
})
}
if (!exists && !isDisabled) {
// Check if not disabled
bb.push(vv)
await operations.createIndex(domain, vv, {
name
})
}
} catch (err: any) {
Analytics.handleError(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) {
for (const c of allIndexes) {

View File

@ -385,7 +385,7 @@ export async function upgradeModel (
await tryMigrate(migrateClient, coreId, [
{
state: 'sparse',
state: 'indexes-v2',
func: upgradeIndexes
}
])