Pad: Parallelize record fetching when checking consistency
parent
096379e6f9
commit
088bb12797
|
@ -649,14 +649,27 @@ class Pad {
|
||||||
pool.eachAttrib((k, v) => {
|
pool.eachAttrib((k, v) => {
|
||||||
if (k === 'author' && v) authorIds.add(v);
|
if (k === 'author' && v) authorIds.add(v);
|
||||||
});
|
});
|
||||||
|
const revs = Stream.range(0, head + 1)
|
||||||
|
.map(async (r) => {
|
||||||
|
const isKeyRev = r === this.getKeyRevisionNumber(r);
|
||||||
|
try {
|
||||||
|
return await Promise.all([
|
||||||
|
r,
|
||||||
|
this.getRevisionChangeset(r),
|
||||||
|
this.getRevisionAuthor(r),
|
||||||
|
this.getRevisionDate(r),
|
||||||
|
isKeyRev,
|
||||||
|
isKeyRev ? this._getKeyRevisionAText(r) : null,
|
||||||
|
]);
|
||||||
|
} catch (err) {
|
||||||
|
err.message = `(pad ${this.id} revision ${r}) ${err.message}`;
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.batch(100).buffer(99);
|
||||||
let atext = Changeset.makeAText('\n');
|
let atext = Changeset.makeAText('\n');
|
||||||
for (let r = 0; r <= head; ++r) {
|
for await (const [r, changeset, authorId, timestamp, isKeyRev, keyAText] of revs) {
|
||||||
try {
|
try {
|
||||||
const [changeset, authorId, timestamp] = await Promise.all([
|
|
||||||
this.getRevisionChangeset(r),
|
|
||||||
this.getRevisionAuthor(r),
|
|
||||||
this.getRevisionDate(r),
|
|
||||||
]);
|
|
||||||
assert(authorId != null);
|
assert(authorId != null);
|
||||||
assert.equal(typeof authorId, 'string');
|
assert.equal(typeof authorId, 'string');
|
||||||
if (authorId) authorIds.add(authorId);
|
if (authorId) authorIds.add(authorId);
|
||||||
|
@ -680,9 +693,7 @@ class Pad {
|
||||||
assert.equal(op.attribs, AttributeMap.fromString(op.attribs, pool).toString());
|
assert.equal(op.attribs, AttributeMap.fromString(op.attribs, pool).toString());
|
||||||
}
|
}
|
||||||
atext = Changeset.applyToAText(changeset, atext, pool);
|
atext = Changeset.applyToAText(changeset, atext, pool);
|
||||||
if (r === this.getKeyRevisionNumber(r)) {
|
if (isKeyRev) assert.deepEqual(keyAText, atext);
|
||||||
assert.deepEqual(await this._getKeyRevisionAText(r), atext);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
err.message = `(pad ${this.id} revision ${r}) ${err.message}`;
|
err.message = `(pad ${this.id} revision ${r}) ${err.message}`;
|
||||||
throw err;
|
throw err;
|
||||||
|
@ -695,16 +706,19 @@ class Pad {
|
||||||
assert(this.chatHead != null);
|
assert(this.chatHead != null);
|
||||||
assert(Number.isInteger(this.chatHead));
|
assert(Number.isInteger(this.chatHead));
|
||||||
assert(this.chatHead >= -1);
|
assert(this.chatHead >= -1);
|
||||||
for (c = 0; c <= this.chatHead; ++c) {
|
const chats = Stream.range(0, this.chatHead + 1)
|
||||||
try {
|
.map(async (c) => {
|
||||||
const msg = await this.getChatMessage(c);
|
try {
|
||||||
assert(msg != null);
|
const msg = await this.getChatMessage(c);
|
||||||
assert(msg instanceof ChatMessage);
|
assert(msg != null);
|
||||||
} catch (err) {
|
assert(msg instanceof ChatMessage);
|
||||||
err.message = `(pad ${this.id} chat message ${c}) ${err.message}`;
|
} catch (err) {
|
||||||
throw err;
|
err.message = `(pad ${this.id} chat message ${c}) ${err.message}`;
|
||||||
}
|
throw err;
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.batch(100).buffer(99);
|
||||||
|
for (const p of chats) await p;
|
||||||
|
|
||||||
await hooks.aCallAll('padCheck', {pad: this});
|
await hooks.aCallAll('padCheck', {pad: this});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue