Skip to content

Commit

Permalink
more robust handling of sync error, fixes zadam#830
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed Jan 18, 2020
1 parent 759e47b commit a6cd250
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/services/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ async function saveLinks(note, content) {
}

const foundLinks = [];
console.log("Scanning", content);

if (note.type === 'text') {
content = findImageLinks(content, foundLinks);
content = findInternalLinks(content, foundLinks);
Expand Down
36 changes: 25 additions & 11 deletions src/services/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,36 @@ function sendMessageToAllClients(message) {
}
}

async function fillInAdditionalProperties(sync) {throw new Error("AAA");
// fill in some extra data needed by the frontend
if (sync.entityName === 'attributes') {
sync.noteId = await sql.getValue(`SELECT noteId
FROM attributes
WHERE attributeId = ?`, [sync.entityId]);
} else if (sync.entityName === 'note_revisions') {
sync.noteId = await sql.getValue(`SELECT noteId
FROM note_revisions
WHERE noteRevisionId = ?`, [sync.entityId]);
} else if (sync.entityName === 'branches') {
const {noteId, parentNoteId} = await sql.getRow(`SELECT noteId, parentNoteId
FROM branches
WHERE branchId = ?`, [sync.entityId]);

sync.noteId = noteId;
sync.parentNoteId = parentNoteId;
}
}

async function sendPing(client) {
const syncData = require('./sync_table').getEntitySyncsNewerThan(lastAcceptedSyncIds[client.id]);

for (const sync of syncData) {
// fill in some extra data needed by the frontend
if (sync.entityName === 'attributes') {
sync.noteId = await sql.getValue(`SELECT noteId FROM attributes WHERE attributeId = ?`, [sync.entityId]);
try {
await fillInAdditionalProperties(sync);
}
else if (sync.entityName === 'note_revisions') {
sync.noteId = await sql.getValue(`SELECT noteId FROM note_revisions WHERE noteRevisionId = ?`, [sync.entityId]);
}
else if (sync.entityName === 'branches') {
const {noteId, parentNoteId} = await sql.getRow(`SELECT noteId, parentNoteId FROM branches WHERE branchId = ?`, [sync.entityId]);

sync.noteId = noteId;
sync.parentNoteId = parentNoteId;
catch (e) {
log.error("Could not fill additional properties for sync " + JSON.stringify(sync)
+ " because of error: " + e.message + ": " + e.stack);
}
}

Expand Down

0 comments on commit a6cd250

Please sign in to comment.