mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-04-22 20:00:30 -05:00
reddit plugin refactoring, performance improvemnts etc.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
const sql = require('./sql');
|
||||
const utils = require('./utils');
|
||||
const sync_table = require('./sync_table');
|
||||
|
||||
async function getNoteIdWithAttribute(name, value) {
|
||||
return await sql.getFirstValue(`SELECT notes.note_id FROM notes JOIN attributes USING(note_id)
|
||||
WHERE notes.is_deleted = 0 AND attributes.name = ? AND attributes.value = ?`, [name, value]);
|
||||
}
|
||||
|
||||
async function createAttribute(noteId, name, value = null, sourceId = null) {
|
||||
const now = utils.nowDate();
|
||||
const attributeId = utils.newAttributeId();
|
||||
|
||||
await sql.insert("attributes", {
|
||||
attribute_id: attributeId,
|
||||
note_id: noteId,
|
||||
name: name,
|
||||
value: value,
|
||||
date_modified: now,
|
||||
date_created: now
|
||||
});
|
||||
|
||||
await sync_table.addAttributeSync(attributeId, sourceId);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getNoteIdWithAttribute,
|
||||
createAttribute
|
||||
};
|
||||
+1
-1
@@ -37,7 +37,7 @@ async function createNewNote(parentNoteId, note, sourceId) {
|
||||
await sql.insert("notes", {
|
||||
note_id: noteId,
|
||||
note_title: note.note_title,
|
||||
note_text: '',
|
||||
note_text: note.note_text ? note.note_text : '',
|
||||
date_created: now,
|
||||
date_modified: now,
|
||||
is_protected: note.is_protected
|
||||
|
||||
@@ -36,8 +36,8 @@ async function addNoteImageSync(noteImageId, sourceId) {
|
||||
await addEntitySync("notes_image", noteImageId, sourceId);
|
||||
}
|
||||
|
||||
async function addAttributeSync(noteImageId, sourceId) {
|
||||
await addEntitySync("attributes", noteImageId, sourceId);
|
||||
async function addAttributeSync(attributeId, sourceId) {
|
||||
await addEntitySync("attributes", attributeId, sourceId);
|
||||
}
|
||||
|
||||
async function addEntitySync(entityName, entityId, sourceId) {
|
||||
|
||||
+12
-1
@@ -99,6 +99,16 @@ function assertArguments() {
|
||||
}
|
||||
}
|
||||
|
||||
async function stopWatch(what, func) {
|
||||
const start = new Date();
|
||||
|
||||
await func();
|
||||
|
||||
const tookMs = new Date().getTime() - start.getTime();
|
||||
|
||||
console.log(`${what} took ${tookMs}ms`);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
randomSecureToken,
|
||||
randomString,
|
||||
@@ -119,5 +129,6 @@ module.exports = {
|
||||
isEmptyOrWhitespace,
|
||||
getDateTimeForFile,
|
||||
sanitizeSql,
|
||||
assertArguments
|
||||
assertArguments,
|
||||
stopWatch
|
||||
};
|
||||
Reference in New Issue
Block a user