From 42c71a18f6e69a718b087faf36df54ca21ef0ad7 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Tue, 20 May 2025 20:59:47 +0200 Subject: [PATCH] get infos from notebooks table when loading the notebook tree structure --- application/store.c | 15 +++++++++++---- application/types.h | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/application/store.c b/application/store.c index 1bef075..7a27179 100644 --- a/application/store.c +++ b/application/store.c @@ -53,7 +53,8 @@ " inner join cols p on c.parent_id = p.resource_id and c.iscollection = 1 \n" \ " where p.depth < 3\n" \ ")\n" \ - "select * from cols\n" \ + "select n.*, r.resource_id as [__resources__resource_id], r.* from cols r\n" \ + "left join notebooks n on r.resource_id = n.resource_id\n" \ "order by path;" #define SQL_NOTEBOOK_GET_NOTES \ @@ -327,7 +328,7 @@ void note_store_reload() { DBUQuery *q = connection->createQuery(connection, NULL); dbuQuerySetSQL(q, SQL_NOTEBOOK_STRUCTURE); dbuQuerySetParamInt64(q, 1, settings_default_node_id); - DBUObjectBuilder *builder = dbuObjectBuilder(resource_class, q, mp->allocator); + DBUObjectBuilder *builder = dbuObjectBuilder(notebook_class, q, mp->allocator); CxList *collections = dbuObjectBuilderGetList(builder); dbuObjectBuilderDestroy(builder); @@ -343,12 +344,18 @@ void note_store_reload() { store->root = NULL; store->trash = NULL; - // key: collection_id value: Collection* + // key: resource_id value: Notebook* CxMap *collection_map = cxHashMapCreate(NULL, CX_STORE_POINTERS, cxListSize(collections) + 16); // convert result list to tree CxIterator i = cxListIterator(collections); - cx_foreach(Resource *, col, i) { + cx_foreach(Notebook *, nb, i) { + // switch link between resource and notebook + Resource *col = nb->resource; + if(!col) { + continue; // error, should not happen + } + col->notebook = nb; CxHashKey key = cx_hash_key(&col->resource_id, sizeof(int64_t)); cxMapPut(collection_map, key, col); if(i.index == 0) { diff --git a/application/types.h b/application/types.h index c83f6d0..5e2a9b0 100644 --- a/application/types.h +++ b/application/types.h @@ -93,6 +93,8 @@ struct Resource { */ CxList *attachments; + Notebook *notebook; + /* * indicates, whether content or bin_content was queried * content_loaded is not a column in the Notes table, however it can be -- 2.43.5