mirror of
https://github.com/zadam/trilium.git
synced 2025-10-30 18:05:55 +01:00
sync / transaction fixes for recent notes
This commit is contained in:
@@ -21,7 +21,7 @@ const recentNotes = (function() {
|
|||||||
function addRecentNote(notePath) {
|
function addRecentNote(notePath) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// we include the note into recent list only if the user stayed on the note at least 5 seconds
|
// we include the note into recent list only if the user stayed on the note at least 5 seconds
|
||||||
if (notePath === noteTree.getCurrentNotePath()) {
|
if (notePath && notePath === noteTree.getCurrentNotePath()) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: baseApiUrl + 'recent-notes/' + encodeURIComponent(notePath),
|
url: baseApiUrl + 'recent-notes/' + encodeURIComponent(notePath),
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ router.get('', auth.checkApiAuth, async (req, res, next) => {
|
|||||||
router.put('/:notePath', auth.checkApiAuth, async (req, res, next) => {
|
router.put('/:notePath', auth.checkApiAuth, async (req, res, next) => {
|
||||||
const notePath = req.params.notePath;
|
const notePath = req.params.notePath;
|
||||||
|
|
||||||
|
await sql.doInTransaction(async() => {
|
||||||
await sql.replace('recent_notes', {
|
await sql.replace('recent_notes', {
|
||||||
note_path: notePath,
|
note_path: notePath,
|
||||||
date_accessed: utils.nowTimestamp(),
|
date_accessed: utils.nowTimestamp(),
|
||||||
@@ -24,14 +25,19 @@ router.put('/:notePath', auth.checkApiAuth, async (req, res, next) => {
|
|||||||
await sync_table.addRecentNoteSync(notePath);
|
await sync_table.addRecentNoteSync(notePath);
|
||||||
|
|
||||||
await options.setOption('start_note_tree_id', notePath);
|
await options.setOption('start_note_tree_id', notePath);
|
||||||
|
});
|
||||||
|
|
||||||
res.send(await getRecentNotes());
|
res.send(await getRecentNotes());
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete('/:notePath', auth.checkApiAuth, async (req, res, next) => {
|
router.delete('/:notePath', auth.checkApiAuth, async (req, res, next) => {
|
||||||
await sql.execute('UPDATE recent_notes SET is_deleted = 1 WHERE note_path = ?', [req.params.notePath]);
|
const notePath = req.params.notePath;
|
||||||
|
|
||||||
await sync_table.addRecentNoteSync(req.params.notePath);
|
await sql.doInTransaction(async() => {
|
||||||
|
await sql.execute('UPDATE recent_notes SET is_deleted = 1 WHERE note_path = ?', [notePath]);
|
||||||
|
|
||||||
|
await sync_table.addRecentNoteSync(notePath);
|
||||||
|
});
|
||||||
|
|
||||||
res.send(await getRecentNotes());
|
res.send(await getRecentNotes());
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user