mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-31 19:02:59 +01:00
db: await more database operations
Co-authored-by: Richard Hansen <rhansen@rhansen.org>
This commit is contained in:
parent
e64462323b
commit
0040f5984e
3 changed files with 19 additions and 21 deletions
|
@ -139,11 +139,11 @@ exports.getRevisionChangeset = async (padID, rev) => {
|
|||
}
|
||||
|
||||
// get the changeset for this revision
|
||||
return pad.getRevisionChangeset(rev);
|
||||
return await pad.getRevisionChangeset(rev);
|
||||
}
|
||||
|
||||
// the client wants the latest changeset, lets return it to him
|
||||
return pad.getRevisionChangeset(head);
|
||||
return await pad.getRevisionChangeset(head);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -376,12 +376,12 @@ Pad.prototype.copy = async function (destinationID, force) {
|
|||
// if force is true and already exists a Pad with the same id, remove that Pad
|
||||
await this.removePadIfForceIsTrueAndAlreadyExist(destinationID, force);
|
||||
|
||||
// copy the 'pad' entry
|
||||
const pad = await this._db.get(`pad:${this.id}`);
|
||||
db.set(`pad:${destinationID}`, pad);
|
||||
|
||||
// copy all relations in parallel
|
||||
const promises = [];
|
||||
// copy all records in parallel
|
||||
const promises = [
|
||||
// Copy the 'pad' entry. This is wrapped in an IIFE so that this._db.get() can run in parallel
|
||||
// with the other record copies done below.
|
||||
(async () => await db.set(`pad:${destinationID}`, await this._db.get(`pad:${this.id}`)))(),
|
||||
];
|
||||
|
||||
// copy all chat messages
|
||||
const chatHead = this.chatHead;
|
||||
|
@ -399,7 +399,7 @@ Pad.prototype.copy = async function (destinationID, force) {
|
|||
promises.push(p);
|
||||
}
|
||||
|
||||
this.copyAuthorInfoToDestinationPad(destinationID);
|
||||
promises.push(this.copyAuthorInfoToDestinationPad(destinationID));
|
||||
|
||||
// wait for the above to complete
|
||||
await Promise.all(promises);
|
||||
|
@ -409,11 +409,8 @@ Pad.prototype.copy = async function (destinationID, force) {
|
|||
await db.setSub(`group:${destGroupID}`, ['pads', destinationID], 1);
|
||||
}
|
||||
|
||||
// delay still necessary?
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
|
||||
// Initialize the new pad (will update the listAllPads cache)
|
||||
await padManager.getPad(destinationID, null); // this runs too early.
|
||||
await padManager.getPad(destinationID, null);
|
||||
|
||||
// let the plugins know the pad was copied
|
||||
await hooks.aCallAll('padCopy', {originalPad: this, destinationID});
|
||||
|
@ -459,11 +456,10 @@ Pad.prototype.removePadIfForceIsTrueAndAlreadyExist = async function (destinatio
|
|||
}
|
||||
};
|
||||
|
||||
Pad.prototype.copyAuthorInfoToDestinationPad = function (destinationID) {
|
||||
Pad.prototype.copyAuthorInfoToDestinationPad = async function (destinationID) {
|
||||
// add the new sourcePad to all authors who contributed to the old one
|
||||
this.getAllAuthors().forEach((authorID) => {
|
||||
authorManager.addPad(authorID, destinationID);
|
||||
});
|
||||
await Promise.all(this.getAllAuthors().map(
|
||||
(authorID) => authorManager.addPad(authorID, destinationID)));
|
||||
};
|
||||
|
||||
Pad.prototype.copyPadWithoutHistory = async function (destinationID, force) {
|
||||
|
@ -481,7 +477,7 @@ Pad.prototype.copyPadWithoutHistory = async function (destinationID, force) {
|
|||
const sourcePad = await padManager.getPad(sourceID);
|
||||
|
||||
// add the new sourcePad to all authors who contributed to the old one
|
||||
this.copyAuthorInfoToDestinationPad(destinationID);
|
||||
await this.copyAuthorInfoToDestinationPad(destinationID);
|
||||
|
||||
// Group pad? Add it to the group's list
|
||||
if (destGroupID) {
|
||||
|
|
|
@ -41,8 +41,10 @@ exports.getReadOnlyId = async (padId) => {
|
|||
// there is no readOnly Entry in the database, let's create one
|
||||
if (readOnlyId == null) {
|
||||
readOnlyId = `r.${randomString(16)}`;
|
||||
db.set(`pad2readonly:${padId}`, readOnlyId);
|
||||
db.set(`readonly2pad:${readOnlyId}`, padId);
|
||||
await Promise.all([
|
||||
db.set(`pad2readonly:${padId}`, readOnlyId),
|
||||
db.set(`readonly2pad:${readOnlyId}`, padId),
|
||||
]);
|
||||
}
|
||||
|
||||
return readOnlyId;
|
||||
|
@ -52,7 +54,7 @@ exports.getReadOnlyId = async (padId) => {
|
|||
* returns the padId for a read only id
|
||||
* @param {String} readOnlyId read only id
|
||||
*/
|
||||
exports.getPadId = (readOnlyId) => db.get(`readonly2pad:${readOnlyId}`);
|
||||
exports.getPadId = async (readOnlyId) => await db.get(`readonly2pad:${readOnlyId}`);
|
||||
|
||||
/**
|
||||
* returns the padId and readonlyPadId in an object for any id
|
||||
|
|
Loading…
Reference in a new issue