mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-12 09:45:30 -05:00
changed for loop to foreach
Signed-off-by: Yannick Bungers <git@innay.de> Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
4eb71d6cad
commit
c6655d767a
1 changed files with 15 additions and 16 deletions
|
@ -14,17 +14,17 @@ import logger = require('../logger');
|
||||||
|
|
||||||
const Op = Sequelize.Op;
|
const Op = Sequelize.Op;
|
||||||
|
|
||||||
var dmpWorker: ChildProcess | null = createDmpWorker()
|
let dmpWorker: ChildProcess | null = createDmpWorker();
|
||||||
var dmpCallbackCache = {}
|
const dmpCallbackCache = {};
|
||||||
|
|
||||||
function createDmpWorker() {
|
function createDmpWorker() {
|
||||||
var worker = childProcess.fork(path.resolve(__dirname, '../workers/dmpWorker.js'), ['ignore'])
|
const worker = childProcess.fork(path.resolve(__dirname, '../workers/dmpWorker.js'), ['ignore']);
|
||||||
logger.debug('dmp worker process started')
|
logger.debug('dmp worker process started')
|
||||||
worker.on('message', function (data: any) {
|
worker.on('message', function (data: any) {
|
||||||
if (!data || !data.msg || !data.cacheKey) {
|
if (!data || !data.msg || !data.cacheKey) {
|
||||||
return logger.error('dmp worker error: not enough data on message')
|
return logger.error('dmp worker error: not enough data on message')
|
||||||
}
|
}
|
||||||
var cacheKey = data.cacheKey
|
const cacheKey = data.cacheKey;
|
||||||
switch (data.msg) {
|
switch (data.msg) {
|
||||||
case 'error':
|
case 'error':
|
||||||
dmpCallbackCache[cacheKey](data.error, null)
|
dmpCallbackCache[cacheKey](data.error, null)
|
||||||
|
@ -44,7 +44,7 @@ function createDmpWorker() {
|
||||||
|
|
||||||
function sendDmpWorker(data, callback) {
|
function sendDmpWorker(data, callback) {
|
||||||
if (!dmpWorker) dmpWorker = createDmpWorker()
|
if (!dmpWorker) dmpWorker = createDmpWorker()
|
||||||
var cacheKey = Date.now() + '_' + shortId.generate()
|
const cacheKey = Date.now() + '_' + shortId.generate();
|
||||||
dmpCallbackCache[cacheKey] = callback
|
dmpCallbackCache[cacheKey] = callback
|
||||||
data = Object.assign(data, {
|
data = Object.assign(data, {
|
||||||
cacheKey: cacheKey
|
cacheKey: cacheKey
|
||||||
|
@ -112,14 +112,13 @@ export class Revision extends Model<Revision> {
|
||||||
},
|
},
|
||||||
order: [['createdAt', 'DESC']]
|
order: [['createdAt', 'DESC']]
|
||||||
}).then(function (revisions) {
|
}).then(function (revisions) {
|
||||||
var data: any[] = []
|
const data: any[] = [];
|
||||||
for (var i = 0; i < revisions.length; i++) {
|
revisions.forEach(function (revision) {
|
||||||
var revision = revisions[i]
|
|
||||||
data.push({
|
data.push({
|
||||||
time: moment(revision.createdAt).valueOf(),
|
time: moment(revision.createdAt).valueOf(),
|
||||||
length: revision.length
|
length: revision.length
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
callback(null, data)
|
callback(null, data)
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
callback(err, null)
|
callback(err, null)
|
||||||
|
@ -197,12 +196,12 @@ export class Revision extends Model<Revision> {
|
||||||
}
|
}
|
||||||
}).then(function (notes) {
|
}).then(function (notes) {
|
||||||
if (notes.length <= 0) return callback(null, notes)
|
if (notes.length <= 0) return callback(null, notes)
|
||||||
var savedNotes: any[] = []
|
const savedNotes: any[] = [];
|
||||||
async.each(notes, function (note: any, _callback) {
|
async.each(notes, function (note: any, _callback) {
|
||||||
// revision saving policy: note not been modified for 5 mins or not save for 10 mins
|
// revision saving policy: note not been modified for 5 mins or not save for 10 mins
|
||||||
if (note.lastchangeAt && note.savedAt) {
|
if (note.lastchangeAt && note.savedAt) {
|
||||||
var lastchangeAt = moment(note.lastchangeAt)
|
const lastchangeAt = moment(note.lastchangeAt);
|
||||||
var savedAt = moment(note.savedAt)
|
const savedAt = moment(note.savedAt);
|
||||||
if (moment().isAfter(lastchangeAt.add(5, 'minutes'))) {
|
if (moment().isAfter(lastchangeAt.add(5, 'minutes'))) {
|
||||||
savedNotes.push(note)
|
savedNotes.push(note)
|
||||||
Revision.saveNoteRevision(note, _callback)
|
Revision.saveNoteRevision(note, _callback)
|
||||||
|
@ -221,7 +220,7 @@ export class Revision extends Model<Revision> {
|
||||||
return callback(err, null)
|
return callback(err, null)
|
||||||
}
|
}
|
||||||
// return null when no notes need saving at this moment but have delayed tasks to be done
|
// return null when no notes need saving at this moment but have delayed tasks to be done
|
||||||
var result = ((savedNotes.length === 0) && (notes.length > savedNotes.length)) ? null : savedNotes
|
const result = ((savedNotes.length === 0) && (notes.length > savedNotes.length)) ? null : savedNotes;
|
||||||
return callback(null, result)
|
return callback(null, result)
|
||||||
})
|
})
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
|
@ -249,9 +248,9 @@ export class Revision extends Model<Revision> {
|
||||||
return callback(err, null)
|
return callback(err, null)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
var latestRevision = revisions[0]
|
const latestRevision = revisions[0];
|
||||||
var lastContent = latestRevision.content || latestRevision.lastContent
|
const lastContent = latestRevision.content || latestRevision.lastContent;
|
||||||
var content = note.content
|
const content = note.content;
|
||||||
sendDmpWorker({
|
sendDmpWorker({
|
||||||
msg: 'create patch',
|
msg: 'create patch',
|
||||||
lastDoc: lastContent,
|
lastDoc: lastContent,
|
||||||
|
|
Loading…
Reference in a new issue