mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-03-13 11:29:04 -05:00
added sync for recent notes
This commit is contained in:
@@ -4,7 +4,7 @@ const options = require('./options');
|
||||
const fs = require('fs-extra');
|
||||
const log = require('./log');
|
||||
|
||||
const APP_DB_VERSION = 26;
|
||||
const APP_DB_VERSION = 27;
|
||||
const MIGRATIONS_DIR = "./migrations";
|
||||
|
||||
async function migrate() {
|
||||
|
||||
@@ -148,6 +148,10 @@ async function addOptionsSync(optName, sourceId) {
|
||||
await addEntitySync("options", optName, sourceId);
|
||||
}
|
||||
|
||||
async function addRecentNoteSync(noteId, sourceId) {
|
||||
await addEntitySync("recent_notes", noteId, sourceId);
|
||||
}
|
||||
|
||||
async function addEntitySync(entityName, entityId, sourceId) {
|
||||
await replace("sync", {
|
||||
entity_name: entityName,
|
||||
@@ -210,5 +214,6 @@ module.exports = {
|
||||
addNoteTreeSync,
|
||||
addNoteReorderingSync,
|
||||
addNoteHistorySync,
|
||||
addOptionsSync
|
||||
addOptionsSync,
|
||||
addRecentNoteSync
|
||||
};
|
||||
@@ -67,6 +67,9 @@ async function pullSync(syncContext) {
|
||||
else if (sync.entity_name === 'options') {
|
||||
await updateOptions(resp, syncContext.sourceId);
|
||||
}
|
||||
else if (sync.entity_name === 'recent_notes') {
|
||||
await updateRecentNotes(resp, syncContext.sourceId);
|
||||
}
|
||||
else {
|
||||
logSyncError("Unrecognized entity type " + sync.entity_name, e);
|
||||
}
|
||||
@@ -123,6 +126,9 @@ async function readAndPushEntity(sync, syncContext) {
|
||||
else if (sync.entity_name === 'options') {
|
||||
entity = await sql.getSingleResult('SELECT * FROM options WHERE opt_name = ?', [sync.entity_id]);
|
||||
}
|
||||
else if (sync.entity_name === 'recent_notes') {
|
||||
entity = await sql.getSingleResult('SELECT * FROM recent_notes WHERE note_id = ?', [sync.entity_id]);
|
||||
}
|
||||
else {
|
||||
logSyncError("Unrecognized entity type " + sync.entity_name, null);
|
||||
}
|
||||
@@ -358,6 +364,18 @@ async function updateOptions(entity, sourceId) {
|
||||
}
|
||||
}
|
||||
|
||||
async function updateRecentNotes(entity, sourceId) {
|
||||
const orig = await sql.getSingleResultOrNull("select * from recent_notes where note_id = ?", [entity.note_id]);
|
||||
|
||||
if (orig === null || orig.date_accessed < entity.date_accessed) {
|
||||
await sql.doInTransaction(async () => {
|
||||
await sql.replace('recent_notes', entity);
|
||||
|
||||
await sql.addRecentNoteSync(entity.note_id, sourceId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (SYNC_SERVER) {
|
||||
log.info("Setting up sync");
|
||||
|
||||
@@ -377,5 +395,6 @@ module.exports = {
|
||||
updateNoteHistory,
|
||||
updateNoteReordering,
|
||||
updateOptions,
|
||||
updateRecentNotes,
|
||||
isSyncSetup
|
||||
};
|
||||
Reference in New Issue
Block a user