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

@@ -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;
}
/**