mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-12 12:47:45 +02:00
UBERF-6540: Fix isIndexable and clean wrong indexed documents (#5347)
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import core, { coreId, DOMAIN_DOC_INDEX_STATE, TxOperations } from '@hcengineering/core'
|
||||
import core, { coreId, DOMAIN_DOC_INDEX_STATE, isClassIndexable, TxOperations } from '@hcengineering/core'
|
||||
import {
|
||||
tryUpgrade,
|
||||
type MigrateOperation,
|
||||
@@ -24,8 +24,22 @@ import {
|
||||
export const coreOperation: MigrateOperation = {
|
||||
async migrate (client: MigrationClient): Promise<void> {
|
||||
// We need to delete all documents in doc index state for missing classes
|
||||
const allDocs = client.hierarchy.getDescendants(core.class.Doc)
|
||||
await client.deleteMany(DOMAIN_DOC_INDEX_STATE, { objectClass: { $nin: allDocs } })
|
||||
const allClasses = client.hierarchy.getDescendants(core.class.Doc)
|
||||
const allIndexed = allClasses.filter((it) => isClassIndexable(client.hierarchy, it))
|
||||
const indexed = new Set(allIndexed)
|
||||
const skipped = allClasses.filter((it) => !indexed.has(it))
|
||||
|
||||
// Next remove all non indexed classes and missing classes as well.
|
||||
const updated = await client.update(
|
||||
DOMAIN_DOC_INDEX_STATE,
|
||||
{ objectClass: { $nin: allIndexed } },
|
||||
{
|
||||
$set: {
|
||||
removed: true
|
||||
}
|
||||
}
|
||||
)
|
||||
console.log('clearing non indexed documents', skipped, updated.updated, updated.matched)
|
||||
},
|
||||
async upgrade (client: MigrationUpgradeClient): Promise<void> {
|
||||
await tryUpgrade(client, coreId, [
|
||||
|
||||
Reference in New Issue
Block a user