mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 19:58:09 +00:00
UBER-266: Fix mongo exceptions (#3267)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
4fad67b6a4
commit
b95066d71a
@ -223,10 +223,8 @@ export async function extractIndexedValues (
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Check if attribute is indexable
|
// Check if attribute is indexable
|
||||||
let keyAttr: AnyAttribute
|
const keyAttr: AnyAttribute | undefined = hierarchy.findAttribute(_class, attr)
|
||||||
try {
|
if (keyAttr === undefined) {
|
||||||
keyAttr = hierarchy.getAttribute(_class, attr)
|
|
||||||
} catch (err: any) {
|
|
||||||
// Skip if there is no attribute.
|
// Skip if there is no attribute.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -617,14 +617,23 @@ abstract class MongoAdapterBase implements DbAdapter {
|
|||||||
async update (domain: Domain, operations: Map<Ref<Doc>, DocumentUpdate<Doc>>): Promise<void> {
|
async update (domain: Domain, operations: Map<Ref<Doc>, DocumentUpdate<Doc>>): Promise<void> {
|
||||||
const coll = this.db.collection(domain)
|
const coll = this.db.collection(domain)
|
||||||
|
|
||||||
try {
|
// remove old and insert new ones
|
||||||
// remove old and insert new ones
|
const ops = Array.from(operations.entries())
|
||||||
const ops = Array.from(operations.entries())
|
let skip = 500
|
||||||
if (ops.length > 0) {
|
while (ops.length > 0) {
|
||||||
const part = ops.splice(0, 500)
|
const part = ops.splice(0, skip)
|
||||||
|
try {
|
||||||
await coll.bulkWrite(
|
await coll.bulkWrite(
|
||||||
part.map((it) => {
|
part.map((it) => {
|
||||||
const { $unset, ...set } = it[1] as any
|
const { $unset, ...set } = it[1] as any
|
||||||
|
if ($unset !== undefined) {
|
||||||
|
for (const k of Object.keys(set)) {
|
||||||
|
if ($unset[k] === '') {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||||
|
delete $unset[k]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
updateOne: {
|
updateOne: {
|
||||||
filter: { _id: it[0] },
|
filter: { _id: it[0] },
|
||||||
@ -636,9 +645,13 @@ abstract class MongoAdapterBase implements DbAdapter {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
} catch (err: any) {
|
||||||
|
if (skip !== 1) {
|
||||||
|
ops.push(...part)
|
||||||
|
skip = 1 // Let's update one by one, to loose only one failed variant.
|
||||||
|
}
|
||||||
|
console.error(err)
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
|
||||||
console.error(err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user