mirror of
https://github.com/status-im/codimd.git
synced 2025-02-11 20:26:26 +00:00
enable noImplicitReturns
Signed-off-by: Raccoon <raccoon@hackmd.io>
This commit is contained in:
parent
da08b3686a
commit
725ba147d3
@ -23,7 +23,8 @@ function createDmpWorker() {
|
|||||||
if (config.debug) logger.info('dmp worker process started')
|
if (config.debug) logger.info('dmp worker process started')
|
||||||
worker.on('message', function (data) {
|
worker.on('message', function (data) {
|
||||||
if (!data || !data.msg || !data.cacheKey) {
|
if (!data || !data.msg || !data.cacheKey) {
|
||||||
return logger.error('dmp worker error: not enough data on message')
|
logger.error('dmp worker error: not enough data on message')
|
||||||
|
return
|
||||||
}
|
}
|
||||||
var cacheKey = data.cacheKey
|
var cacheKey = data.cacheKey
|
||||||
switch (data.msg) {
|
switch (data.msg) {
|
||||||
|
@ -533,7 +533,10 @@ export function queueForDisconnect(socket) {
|
|||||||
if (Object.keys(note.users).length === 0) {
|
if (Object.keys(note.users).length === 0) {
|
||||||
if (note.server.isDirty) {
|
if (note.server.isDirty) {
|
||||||
exports.updateNote(note, function (err, _note) {
|
exports.updateNote(note, function (err, _note) {
|
||||||
if (err) return logger.error('disconnect note failed: ' + err)
|
if (err) {
|
||||||
|
logger.error('disconnect note failed: ' + err)
|
||||||
|
return
|
||||||
|
}
|
||||||
// clear server before delete to avoid memory leaks
|
// clear server before delete to avoid memory leaks
|
||||||
note.server.document = ''
|
note.server.document = ''
|
||||||
note.server.operations = []
|
note.server.operations = []
|
||||||
@ -657,7 +660,7 @@ function operationCallback(socket, operation) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: test it
|
// TODO: test it
|
||||||
export function updateHistory(userId, note, time) {
|
export function updateHistory(userId, note, time?: any) {
|
||||||
var noteId = note.alias ? note.alias : models.Note.encodeNoteId(note.id)
|
var noteId = note.alias ? note.alias : models.Note.encodeNoteId(note.id)
|
||||||
if (note.server) history.updateHistory(userId, noteId, note.server.document, time)
|
if (note.server) history.updateHistory(userId, noteId, note.server.document, time)
|
||||||
}
|
}
|
||||||
@ -687,7 +690,7 @@ function getUniqueColorPerNote(noteId, maxAttempt = 10) {
|
|||||||
function queueForConnect(socket) {
|
function queueForConnect(socket) {
|
||||||
connectProcessQueue.push(socket.id, async function () {
|
connectProcessQueue.push(socket.id, async function () {
|
||||||
try {
|
try {
|
||||||
const noteId = await exports.parseNoteIdFromSocketAsync(socket)
|
const noteId = await exports.parseNoteIdFromSocketAsync(socket) as string
|
||||||
if (!noteId) {
|
if (!noteId) {
|
||||||
return exports.failConnection(404, 'note id not found', socket)
|
return exports.failConnection(404, 'note id not found', socket)
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,9 @@ export class CleanDanglingUserJob {
|
|||||||
}
|
}
|
||||||
return callback(null, null)
|
return callback(null, null)
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
if (err) return logger.error('cleaner error', err)
|
if (err) {
|
||||||
|
logger.error('cleaner error', err)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,9 @@ export class SaveRevisionJob {
|
|||||||
saveRevision() {
|
saveRevision() {
|
||||||
if (this.getSaverSleep()) return
|
if (this.getSaverSleep()) return
|
||||||
models.Revision.saveAllNotesRevision((err, notes) => {
|
models.Revision.saveAllNotesRevision((err, notes) => {
|
||||||
if (err) return logger.error('revision saver failed: ' + err)
|
if (err) {
|
||||||
|
logger.error('revision saver failed: ' + err)
|
||||||
|
}
|
||||||
if (notes && notes.length <= 0) {
|
if (notes && notes.length <= 0) {
|
||||||
this.setSaverSleep(true)
|
this.setSaverSleep(true)
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,14 @@ import * as logger from "../logger";
|
|||||||
var dmp = new DiffMatchPatch()
|
var dmp = new DiffMatchPatch()
|
||||||
process.on('message', function (data) {
|
process.on('message', function (data) {
|
||||||
if (!data || !data.msg || !data.cacheKey) {
|
if (!data || !data.msg || !data.cacheKey) {
|
||||||
return logger.error('dmp worker error: not enough data')
|
logger.error('dmp worker error: not enough data')
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
switch (data.msg) {
|
switch (data.msg) {
|
||||||
case 'create patch':
|
case 'create patch':
|
||||||
if (!Object.hasOwnProperty.call(data, 'lastDoc') || !Object.hasOwnProperty.call(data, 'currDoc')) {
|
if (!Object.hasOwnProperty.call(data, 'lastDoc') || !Object.hasOwnProperty.call(data, 'currDoc')) {
|
||||||
return logger.error('dmp worker error: not enough data on create patch')
|
logger.error('dmp worker error: not enough data on create patch')
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var patch = createPatch(data.lastDoc, data.currDoc)
|
var patch = createPatch(data.lastDoc, data.currDoc)
|
||||||
@ -52,9 +54,10 @@ process.on('message', function (data) {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
return null
|
||||||
})
|
})
|
||||||
|
|
||||||
function createPatch (lastDoc, currDoc) {
|
function createPatch(lastDoc, currDoc) {
|
||||||
var msStart = (new Date()).getTime()
|
var msStart = (new Date()).getTime()
|
||||||
var diff = dmp.diff_main(lastDoc, currDoc)
|
var diff = dmp.diff_main(lastDoc, currDoc)
|
||||||
var patch = dmp.patch_make(lastDoc, diff)
|
var patch = dmp.patch_make(lastDoc, diff)
|
||||||
@ -67,7 +70,7 @@ function createPatch (lastDoc, currDoc) {
|
|||||||
return patch
|
return patch
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRevision (revisions, count) {
|
function getRevision(revisions, count) {
|
||||||
var msStart = (new Date()).getTime()
|
var msStart = (new Date()).getTime()
|
||||||
var startContent = null
|
var startContent = null
|
||||||
var lastPatch = []
|
var lastPatch = []
|
||||||
@ -91,7 +94,11 @@ function getRevision (revisions, count) {
|
|||||||
for (let i = 0, l = applyPatches.length; i < l; i++) {
|
for (let i = 0, l = applyPatches.length; i < l; i++) {
|
||||||
for (let j = 0, m = applyPatches[i].diffs.length; j < m; j++) {
|
for (let j = 0, m = applyPatches[i].diffs.length; j < m; j++) {
|
||||||
var diff = applyPatches[i].diffs[j]
|
var diff = applyPatches[i].diffs[j]
|
||||||
if (diff[0] === DiffMatchPatch.DIFF_INSERT) { diff[0] = DiffMatchPatch.DIFF_DELETE } else if (diff[0] === DiffMatchPatch.DIFF_DELETE) { diff[0] = DiffMatchPatch.DIFF_INSERT }
|
if (diff[0] === DiffMatchPatch.DIFF_INSERT) {
|
||||||
|
diff[0] = DiffMatchPatch.DIFF_DELETE
|
||||||
|
} else if (diff[0] === DiffMatchPatch.DIFF_DELETE) {
|
||||||
|
diff[0] = DiffMatchPatch.DIFF_INSERT
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user