Fix backup hashing (#3939)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2023-11-04 17:47:26 +07:00 committed by GitHub
parent a2c861d0c4
commit 429574ce1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -594,10 +594,10 @@ abstract class MongoAdapterBase implements DbAdapter {
return undefined return undefined
} }
let digest = (d as any)['%hash%'] let digest = (d as any)['%hash%']
if (digest == null) {
if ('%hash%' in d) { if ('%hash%' in d) {
delete d['%hash%'] delete d['%hash%']
} }
if (digest == null) {
const doc = JSON.stringify(d) const doc = JSON.stringify(d)
const hash = createHash('sha256') const hash = createHash('sha256')
hash.update(doc) hash.update(doc)
@ -646,11 +646,13 @@ abstract class MongoAdapterBase implements DbAdapter {
async load (domain: Domain, docs: Ref<Doc>[]): Promise<Doc[]> { async load (domain: Domain, docs: Ref<Doc>[]): Promise<Doc[]> {
return this.stripHash( return this.stripHash(
this.stripHash(
await this.db await this.db
.collection(domain) .collection(domain)
.find<Doc>({ _id: { $in: docs } }) .find<Doc>({ _id: { $in: docs } })
.toArray() .toArray()
) )
)
} }
async upload (domain: Domain, docs: Doc[]): Promise<void> { async upload (domain: Domain, docs: Doc[]): Promise<void> {
@ -664,7 +666,7 @@ abstract class MongoAdapterBase implements DbAdapter {
part.map((it) => ({ part.map((it) => ({
replaceOne: { replaceOne: {
filter: { _id: it._id }, filter: { _id: it._id },
replacement: it, replacement: { ...it, '%hash%': '' },
upsert: true upsert: true
} }
})) }))
@ -696,7 +698,7 @@ abstract class MongoAdapterBase implements DbAdapter {
updateOne: { updateOne: {
filter: { _id: it[0] }, filter: { _id: it[0] },
update: { update: {
$set: set, $set: { ...set, '%hash%': '' },
...($unset !== undefined ? { $unset } : {}) ...($unset !== undefined ? { $unset } : {})
} }
} }