added getOwnedAttribute() without attr inheritance which can speed up bulk operations significantly

This commit is contained in:
zadam 2019-09-07 20:43:59 +02:00
parent ca8b603bd9
commit 3bf8546d51
2 changed files with 25 additions and 3 deletions

View file

@ -51,7 +51,7 @@
"imagemin-mozjpeg": "8.0.0",
"imagemin-pngquant": "8.0.0",
"ini": "1.3.5",
"jimp": "0.7.0",
"jimp": "0.8.0",
"mime-types": "2.1.24",
"moment": "2.24.0",
"multer": "1.4.2",

View file

@ -196,8 +196,30 @@ class Note extends Entity {
/**
* @returns {Promise<Attribute[]>} attributes belonging to this specific note (excludes inherited attributes)
*/
async getOwnedAttributes() {
return await repository.getEntities(`SELECT * FROM attributes WHERE isDeleted = 0 AND noteId = ?`, [this.noteId]);
async getOwnedAttributes(type, name) {
let query = `SELECT * FROM attributes WHERE isDeleted = 0 AND noteId = ?`;
const params = [this.noteId];
if (type) {
query += ` AND type = ?`;
params.push(type);
}
if (name) {
query += ` AND name = ?`;
params.push(name);
}
return await repository.getEntities(query, params);
}
/**
* @returns {Promise<Attribute>} attribute belonging to this specific note (excludes inherited attributes)
*/
async getOwnedAttribute(type, name) {
const attrs = await this.getOwnedAttributes(type, name);
return attrs.length > 0 ? attrs[0] : null;
}
/**